Ticket #4046: related.py.patch
File related.py.patch, 1.7 KB (added by , 17 years ago) |
---|
-
django/db/models/fields/related.py
552 552 setattr(cls, related.get_accessor_name(), ForeignRelatedObjectsDescriptor(related)) 553 553 554 554 def formfield(self, **kwargs): 555 defaults = {'form_class': forms.ModelChoiceField, 'queryset': self.rel.to._default_manager. all()}555 defaults = {'form_class': forms.ModelChoiceField, 'queryset': self.rel.to._default_manager.complex_filter(self.rel.limit_choices_to or {})} 556 556 defaults.update(kwargs) 557 557 return super(ForeignKey, self).formfield(**defaults) 558 558 … … 628 628 cls._meta.one_to_one_field = self 629 629 630 630 def formfield(self, **kwargs): 631 defaults = {'form_class': forms.ModelChoiceField, 'queryset': self.rel.to._default_manager. all()}631 defaults = {'form_class': forms.ModelChoiceField, 'queryset': self.rel.to._default_manager.complex_filter(self.rel.limit_choices_to or {})} 632 632 defaults.update(kwargs) 633 633 return super(OneToOneField, self).formfield(**defaults) 634 634 … … 760 760 setattr(instance, self.attname, data) 761 761 762 762 def formfield(self, **kwargs): 763 defaults = {'form_class': forms.ModelMultipleChoiceField, 'queryset': self.rel.to._default_manager. all()}763 defaults = {'form_class': forms.ModelMultipleChoiceField, 'queryset': self.rel.to._default_manager.complex_filter(self.rel.limit_choices_to or {})} 764 764 defaults.update(kwargs) 765 765 # If initial is passed in, it's a list of related objects, but the 766 766 # MultipleChoiceField takes a list of IDs.