Fix issue1811: take limit_choices_to into account with FK

This commit is contained in:
Adrien Brunet 2018-12-20 17:35:04 +01:00
parent 63e6bbfd36
commit 2d48dd4e4c

View File

@ -169,6 +169,12 @@ class RelatedField(Field):
# for the field.
# Eg: 'MyRelationship(queryset=ExampleModel.objects.all())'
queryset = queryset.all()
if hasattr(self.parent, "Meta") and hasattr(self.parent.Meta, "model"):
queryset = queryset.filter(
**self.parent.Meta.model._meta.get_field(
self.source
).get_limit_choices_to()
)
return queryset
def use_pk_only_optimization(self):