Friday, November 17, 2017

Dynamically change model managers after initial queryset instanciation

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.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/84ddd49e-60c9-411a-b877-2fa8bbdc34c1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment