Ticket #4046: formfield_patch.diff

File formfield_patch.diff, 995 bytes (added by webograph <webograph@…>, 8 years ago)
  • django/db/models/fields/related.py

     
    553553        setattr(cls, related.get_accessor_name(), ForeignRelatedObjectsDescriptor(related))
    554554
    555555    def formfield(self, **kwargs):
    556         defaults = {'queryset': self.rel.to._default_manager.all(), 'required': not self.blank, 'label': capfirst(self.verbose_name), 'help_text': self.help_text}
     556        defaults = {'required': not self.blank, 'label': capfirst(self.verbose_name), 'help_text': self.help_text}
     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)
    557561        defaults.update(kwargs)
    558562        return forms.ModelChoiceField(**defaults)
    559563
Back to Top