Ticket #4046: formfield_patch.2.diff
File formfield_patch.2.diff, 1.6 KB (added by , 18 years ago) |
---|
-
django/db/models/fields/related.py
553 553 setattr(cls, related.get_accessor_name(), ForeignRelatedObjectsDescriptor(related)) 554 554 555 555 def formfield(self, **kwargs): 556 defaults = {'queryset': self.rel.to._default_manager.all(), 'required': not self.blank, 'label': capfirst(self.verbose_name), 'help_text': self.help_text} 556 defaults = {'required': not self.blank, 'label': capfirst(self.verbose_name), 'help_text': self.help_text} 557 if hasattr(self.rel.limit_choices_to, 'get_sql'): 558 defaults['queryset']=self.rel.to._default_manager.filter(self.rel.limit_choices_to) 559 else: 560 defaults['queryset']=self.rel.to._default_manager.filter(**self.rel.limit_choices_to) 557 561 defaults.update(kwargs) 558 562 return forms.ModelChoiceField(**defaults) 559 563 -
django/newforms/models.py
161 161 return None 162 162 try: 163 163 value = self.queryset.model._default_manager.get(pk=value) 164 if value not in self.queryset: raise self.queryset.model.DoesNotExist, "The specified object exists but is not among the choices." 164 165 except self.queryset.model.DoesNotExist: 165 166 raise ValidationError(gettext(u'Select a valid choice. That choice is not one of the available choices.')) 166 167 return value