Get Call Stacks for Classes in Models

11 views
Skip to first unread message

Utkarsh

unread,
May 26, 2015, 4:56:54 PM5/26/15
to django...@googlegroups.com

Hi!

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!
Reply all
Reply to author
Forward
0 new messages