Explanation of contribute_to_class
Posted
by anon.
on Stack Overflow
See other posts from Stack Overflow
or by anon.
Published on 2010-03-01T17:02:49Z
Indexed on
2010/04/19
2:33 UTC
Read the original article
Hit count: 285
django
|django-models
I'm attempted to extend code, and have come across an issue, I don't understand a line of code. I know the outcome of it - but I don't understand how it happens and am naturally enough scared to change it.
The line of code I've come across is this:
MyGenericRelation().contribute_to_class(model, 'field_name')
The result of this code is a field with 'field_name' is added to the 'model' and from what I gather the objects inside the field are a list of type X (part of MyGenericRelation).
I'm wondering if anyone can explain how this works.
As in, why do I get a list of X objects attached to 'field_name' and if does it have to be generic relations prior to contribute_to_class or would using an actual model type, say 'Y' just give me a list of Y's.
To be honest, I am more interested in the affect and functionality of the contribute_to_class method.
© Stack Overflow or respective owner