Dynamically change model managers after initial queryset instanciation

45 views
Skip to first unread message

Jason

unread,
Nov 17, 2017, 8:18:03 AM11/17/17
to Django users
Let's say I have a Poll object with two managers attached like so:

class Poll(models.Model):
   
#fields here
   
   objects
= PollManager()
   subjects
= SubjectManager()

is it possible to dynamically change which manager is used to make which query after the initial call?  For example

results = Poll.objects.all()
results
.filter(some_field=some_value) # execute filter on queryset using default Poll manager
results
.changeManager(subjects) # change queryset's manager to different Poll manager
district_results
= results.aggregate_district(district = some_district) # execute method in alternative Poll manager


There's nothing in the documentation to suggest this has been considered, nor in the codebase.
Reply all
Reply to author
Forward
0 new messages