Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

newforms-admin: Fixed #4046 - ForeignKey's formfield does not respect…

… limit_choices_to. Thanks ubernostrum, programmerq

git-svn-id: http://code.djangoproject.com/svn/django/branches/newforms-admin@7733 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 0ad37188cf999ff0db1b0b09a82eaf86e7e30c9b 1 parent 420f19a
@spookylukey spookylukey authored
Showing with 2 additions and 2 deletions.
  1. +2 −2 django/db/models/fields/related.py
View
4 django/db/models/fields/related.py
@@ -672,7 +672,7 @@ def contribute_to_related_class(self, cls, related):
setattr(cls, related.get_accessor_name(), ForeignRelatedObjectsDescriptor(related))
def formfield(self, **kwargs):
- defaults = {'form_class': forms.ModelChoiceField, 'queryset': self.rel.to._default_manager.all()}
+ defaults = {'form_class': forms.ModelChoiceField, 'queryset': self.rel.to._default_manager.complex_filter(self.rel.limit_choices_to)}
defaults.update(kwargs)
return super(ForeignKey, self).formfield(**defaults)
@@ -810,7 +810,7 @@ def save_form_data(self, instance, data):
setattr(instance, self.attname, data)
def formfield(self, **kwargs):
- defaults = {'form_class': forms.ModelMultipleChoiceField, 'queryset': self.rel.to._default_manager.all()}
+ defaults = {'form_class': forms.ModelMultipleChoiceField, 'queryset': self.rel.to._default_manager.complex_filter(self.rel.limit_choices_to)}
defaults.update(kwargs)
# If initial is passed in, it's a list of related objects, but the
# MultipleChoiceField takes a list of IDs.

0 comments on commit 0ad3718

Please sign in to comment.
Something went wrong with that request. Please try again.