mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-01 11:00:13 +03:00
Fix issue1811: take limit_choices_to into account with FK
This commit is contained in:
parent
63e6bbfd36
commit
2d48dd4e4c
|
@ -169,6 +169,12 @@ class RelatedField(Field):
|
||||||
# for the field.
|
# for the field.
|
||||||
# Eg: 'MyRelationship(queryset=ExampleModel.objects.all())'
|
# Eg: 'MyRelationship(queryset=ExampleModel.objects.all())'
|
||||||
queryset = queryset.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
|
return queryset
|
||||||
|
|
||||||
def use_pk_only_optimization(self):
|
def use_pk_only_optimization(self):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user