Code

Ticket #4046: 4046.qsrf.diff

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

for svn trunk after qs-rf merge

Line 
1Index: django/db/models/fields/related.py
2===================================================================
3--- django/db/models/fields/related.py (revision 7498)
4+++ django/db/models/fields/related.py (working copy)
5@@ -669,7 +669,7 @@ class ForeignKey(RelatedField, Field):
6         setattr(cls, related.get_accessor_name(), ForeignRelatedObjectsDescriptor(related))
7 
8     def formfield(self, **kwargs):
9-        defaults = {'form_class': forms.ModelChoiceField, 'queryset': self.rel.to._default_manager.all()}
10+        defaults = {'form_class': forms.ModelChoiceField, 'queryset': self.rel.to._default_manager.complex_filter(self.rel.limit_choices_to)}
11         defaults.update(kwargs)
12         return super(ForeignKey, self).formfield(**defaults)
13 
14@@ -823,7 +823,7 @@ class ManyToManyField(RelatedField, Field):
15         setattr(instance, self.attname, data)
16 
17     def formfield(self, **kwargs):
18-        defaults = {'form_class': forms.ModelMultipleChoiceField, 'queryset': self.rel.to._default_manager.all()}
19+        defaults = {'form_class': forms.ModelMultipleChoiceField, 'queryset': self.rel.to._default_manager.complex_filter(self.rel.limit_choices_to)}
20         defaults.update(kwargs)
21         # If initial is passed in, it's a list of related objects, but the
22         # MultipleChoiceField takes a list of IDs.