DynamicRelationField ignores queryset param
See original GitHub issueThe code below always returns all the units
associated with the curriculum
being serialized, and ignores the filter.
class CurriculumSerializer(DynamicModelSerializer):
units = DynamicRelationField('UnitSerializer', many=True, queryset=Unit.objects.filter(id=1))
class Meta:
model = Curriculum
name = 'curriculum'
fields = ('id', 'units')
class UnitSerializer(DynamicModelSerializer):
class Meta:
model = Unit
name = 'unit'
fields = ('id',)
When offloading the queryset to a function with an embedded print or ipdb, such as
def get_unit_queryset(field):
print 'IS THIS EVER HAPPENING?"
return Unit.objects.filter(id=1)
the result is the same and the print statement is never executed. The function is never called.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:4
- Comments:9 (4 by maintainers)
Top Results From Across the Web
Dynamic REST Tutorial — Dynamic REST 1.3.15 documentation
Notes: The function mapped to a queryset should accept one parameter, which is the field (i.e. a DynamicRelationField instance) and return a QuerySet...
Read more >Why queryset.only() is ignored when using serializers?
I am using Django and REST Framework for my app. I want to retrieve distinct values of 1 column in a django model,...
Read more >ordering direction · Issue #171 · AltSchool/dynamic-rest - GitHub
When looking up the QuerySet documentation to achieve this, I found out you can add a minus sign before the column names given...
Read more >django-rest-models Documentation - Read the Docs
Just keep in mind that the backend is not a SGDB and it may not be performant on all queryset, and that some...
Read more >dynamic-rest 1.3.14 - PyPI
location = DynamicRelationField('LocationSerializer') ... "sideload") relationships can be expressed with the `include[]` query parameter.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Most of the magic happens when using filter_queryset where it uses the DynamicFilterBackend. When you are using list_route or detail route I guess you wont be filtering with self.filter_queryset, queryset argument wont be called and you also lose out on the prefetch optimization etc. For anyone looking out for solution make a subclass of the DynamicFilterBackend and call filter_queryset which would set the serializer too else it would end up getting it from get_queryset method. I found it cleaner to use multiple model viewset for my use case and subclassing the backend to be really a messed up hack. If i come across a need for it later on or if i find time, will make a gist of it. If any one wants to write a solution meanwhile I can help out
@simkimsia Yes!