Ticket #3401: char_field_with_choices.patch

File char_field_with_choices.patch, 1016 bytes (added by anton@…, 18 years ago)

patch that fixes the issue

  • django/db/models/fields/__init__.py

     
    417417        return str(value)
    418418
    419419    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}
    421421        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)
    423428
    424429# TODO: Maybe move this into contrib, because it's specialized.
    425430class CommaSeparatedIntegerField(CharField):
Back to Top