Ticket #3401: char_field_with_choices.patch
File char_field_with_choices.patch, 1016 bytes (added by , 18 years ago) |
---|
-
django/db/models/fields/__init__.py
417 417 return str(value) 418 418 419 419 def formfield(self, **kwargs): 420 defaults = {' max_length': self.maxlength, 'required': not self.blank, 'label': capfirst(self.verbose_name), 'help_text': self.help_text}420 defaults = {'required': not self.blank, 'label': capfirst(self.verbose_name), 'help_text': self.help_text} 421 421 defaults.update(kwargs) 422 return forms.CharField(**defaults) 422 if len(self.choices) == 0: 423 defaults['max_length'] = self.maxlength 424 return forms.CharField(**defaults) 425 else: 426 defaults['choices'] = self.get_choices() 427 return forms.ChoiceField(**defaults) 423 428 424 429 # TODO: Maybe move this into contrib, because it's specialized. 425 430 class CommaSeparatedIntegerField(CharField):