Tuesday, May 26, 2015

Get Call Stacks for Classes in Models


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!

--
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/ffe7bc52-66c7-40d6-b174-b7c724496a68%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment