Determine which QuerySetAPI method is called

45 Views Asked by At

I am trying to log overridden calls to QuerySetAPI Say I am calling Example.objects.filter(id=1) and I have following code in Models.py

objects = MyManager()

and in MyManager I have-

class MyManager(Manager): 
   def get_query_set(self):
       # logging stuff I am doing
       return super(MyManager, self).get_query_set()

How do I get the method name (i.e. filter here) in MyManager->get_query_set()? Is there a way to do that without using inspect stack()?

1

There are 1 best solutions below

2
On

The filter comes from the QuerySet object that get_query_set from the Manager returns. The filter function is there: https://github.com/django/django/blob/04e8d890aec8e996d568565555164a27a6a76057/django/db/models/query.py#L778