I've created year dropdown field. Here is a code. It is showing in admin section. But when i tried to save the field.
I get validation error "Value u'2013' is not a valid choice"
Can someone help me? thanks
# fields.py
import datetime
from django.db import models
YEAR_CHOICES = []
for r in range(1980, (datetime.datetime.now().year+1)):
YEAR_CHOICES.append((r, r))
class YearDropdownField(models.CharField):
def __init__(self, *args, **kwargs):
kwargs.setdefault('editable', True)
kwargs.setdefault('max_length', 4)
kwargs.setdefault('choices', YEAR_CHOICES)
kwargs.setdefault('default', datetime.datetime.now().year)
super(YearDropdownField, self).__init__(*args, **kwargs)
# models.py
year = YearDropdownField(_('Year'))