Ticket #4046: 4046.qsrf.diff

File 4046.qsrf.diff, 1.3 KB (added by programmerq, 7 years ago)

for svn trunk after qs-rf merge

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

    class ForeignKey(RelatedField, Field): 
    669669        setattr(cls, related.get_accessor_name(), ForeignRelatedObjectsDescriptor(related))
    670670
    671671    def formfield(self, **kwargs):
    672         defaults = {'form_class': forms.ModelChoiceField, 'queryset': self.rel.to._default_manager.all()}
     672        defaults = {'form_class': forms.ModelChoiceField, 'queryset': self.rel.to._default_manager.complex_filter(self.rel.limit_choices_to)}
    673673        defaults.update(kwargs)
    674674        return super(ForeignKey, self).formfield(**defaults)
    675675
    class ManyToManyField(RelatedField, Field): 
    823823        setattr(instance, self.attname, data)
    824824
    825825    def formfield(self, **kwargs):
    826         defaults = {'form_class': forms.ModelMultipleChoiceField, 'queryset': self.rel.to._default_manager.all()}
     826        defaults = {'form_class': forms.ModelMultipleChoiceField, 'queryset': self.rel.to._default_manager.complex_filter(self.rel.limit_choices_to)}
    827827        defaults.update(kwargs)
    828828        # If initial is passed in, it's a list of related objects, but the
    829829        # MultipleChoiceField takes a list of IDs.
Back to Top