Ticket #4046: related.py.patch

File related.py.patch, 1.7 KB (added by Jan Rademaker <j.rademaker@…>, 17 years ago)

Patch for ForeignKey, OneToOneField, ManyToManyField, no validation

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

     
    552552        setattr(cls, related.get_accessor_name(), ForeignRelatedObjectsDescriptor(related))
    553553
    554554    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 {})}
    556556        defaults.update(kwargs)
    557557        return super(ForeignKey, self).formfield(**defaults)
    558558
     
    628628            cls._meta.one_to_one_field = self
    629629
    630630    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 {})}
    632632        defaults.update(kwargs)
    633633        return super(OneToOneField, self).formfield(**defaults)
    634634
     
    760760        setattr(instance, self.attname, data)
    761761       
    762762    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 {})}
    764764        defaults.update(kwargs)
    765765        # If initial is passed in, it's a list of related objects, but the
    766766        # MultipleChoiceField takes a list of IDs.
Back to Top