Call stacks for Model classes

65 views
Skip to first unread message

malhar

unread,
May 26, 2015, 2:13:17 PM5/26/15
to django-d...@googlegroups.com

So, there is a huge Django app with multiple classes in Model. I am interested in getting call stacks of some classes. I have few questions in the approach and few questions regarding the implementation. I am using Django 1.4.20 and python 2.7

1. What if we decide to write a decorator for the class/ methods? 
Ex. 
@trackitdown
Class A(models.Model):

or 
@trackitdown
def some_method(): # method in models.py

This is because I do not want to disturb the existing code. I wish to achieve following-
I. If it is a class, track all "calls" whenever QuerySetAPI methods, save, delete is called. 
II. while doing following-
objects =classWhichIsAManager()# overriding default manager Custom manager

this should be decorator's task.
III. override using get_query_set() , and save(), delete()

How do you see this approach? I obviously was not able to implement this because of peculiar behavior of Model and ModelBase.

2. Is it okay to decorate a class, define decorator as a class and override methods in it? How much is this encouraged?

3. If I use Mixins, and try to implement the same, I still do not get how do we override 
objects=classWhichIsAManager()

outside the model class? that too without loosing attributes of original model class.

4. Having said this, I wish to implement a library which will take care calls stacks of model classes/ methods. 

Is there a fundamental flaw in my approach? I can see that I am trying to play with some unknown business of ModelBase(Foreign Key constraints, etc) New approaches and comments are equally welcome!








Shai Berger

unread,
May 26, 2015, 3:12:53 PM5/26/15
to django-d...@googlegroups.com
Hi,

Please ask questions about developing with Django on the django-users group.
This group is for discussions about the development of Django itself.

(as a general rule: decorating single methods should work fine; trying to use
decorators on model classes will probably be painful. These classes use
special metaclasses which make them behave differently in many respects).

Thanks,
Shai.
Reply all
Reply to author
Forward
0 new messages