0

I use Django 1.8 version.

my model has birthday column.

class UserProfile(models.Model):
    user = models.OneToOneField(User)
    birthday = models.DateField (verbose_name=u'birthday')
    # ...

it is form for model.

class UserProfileForm(forms.ModelForm):
    slug_field = 'user_slug'

    class Meta:
        model = UserProfile
        fields = (
            'birthday',
        )

I'd like to set who are 10-100 age person.

I guess I should use SelectDateWidget.

import datetime
from django.forms import extras

class UserProfileForm(forms.ModelForm):
    slug_field = 'user_slug'
    now = datetime.datetime.now()
    DOY = tuple(n for n in range(now.year-100, now.year-9))
    birthday = forms.DateField(widget=extras.SelectDateWidget(years = DOY))

Is it good way? or Could you tell me nice idea?

ferrangb
  • 2,012
  • 2
  • 20
  • 34
shinriyo
  • 344
  • 3
  • 17

1 Answers1

0

To validate a form field, you could use a clean_FIELDNAME() method inside your form class. Check out the documentation and this answer.

Community
  • 1
  • 1
mikeser
  • 86
  • 1
  • 5