Ticket #4046: formfield_patch.3.diff
File formfield_patch.3.diff, 1.5 KB (added by , 18 years ago) |
---|
-
django/newforms/models.py
169 169 return None 170 170 try: 171 171 value = self.queryset.model._default_manager.get(pk=value) 172 if value not in self.queryset: 173 raise self.queryset.model.DoesNotExist(gettext(u'Select a valid choice. That choice is not one of the available choices.')) 172 174 except self.queryset.model.DoesNotExist: 173 175 raise ValidationError(gettext(u'Select a valid choice. That choice is not one of the available choices.')) 174 176 return value -
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 = {'form_class': forms.ModelChoiceField, 'queryset': self.rel.to._default_manager.all()} 556 defaults = {'form_class': forms.ModelChoiceField} 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) 561 557 562 defaults.update(kwargs) 558 563 return super(ForeignKey, self).formfield(**defaults) 559 564