Ticket #4046: 4046.diff

File 4046.diff, 1.7 KB (added by James Bennett, 17 years ago)

Patch for current trunk

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

     
    549549        setattr(cls, related.get_accessor_name(), ForeignRelatedObjectsDescriptor(related))
    550550
    551551    def formfield(self, **kwargs):
    552         defaults = {'form_class': forms.ModelChoiceField, 'queryset': self.rel.to._default_manager.all()}
     552        defaults = {'form_class': forms.ModelChoiceField, 'queryset': self.rel.to._default_manager.complex_filter(self.rel.limit_choices_to)}
    553553        defaults.update(kwargs)
    554554        return super(ForeignKey, self).formfield(**defaults)
    555555
     
    625625            cls._meta.one_to_one_field = self
    626626
    627627    def formfield(self, **kwargs):
    628         defaults = {'form_class': forms.ModelChoiceField, 'queryset': self.rel.to._default_manager.all()}
     628        defaults = {'form_class': forms.ModelChoiceField, 'queryset': self.rel.to._default_manager.complex_filter(self.rel.limit_choices_to)}
    629629        defaults.update(kwargs)
    630630        return super(OneToOneField, self).formfield(**defaults)
    631631
     
    757757        setattr(instance, self.attname, data)
    758758       
    759759    def formfield(self, **kwargs):
    760         defaults = {'form_class': forms.ModelMultipleChoiceField, 'queryset': self.rel.to._default_manager.all()}
     760        defaults = {'form_class': forms.ModelMultipleChoiceField, 'queryset': self.rel.to._default_manager.complex_filter(self.rel.limit_choices_to)}
    761761        defaults.update(kwargs)
    762762        # If initial is passed in, it's a list of related objects, but the
    763763        # MultipleChoiceField takes a list of IDs.
Back to Top