Question about model attributes

18 views
Skip to first unread message

Ankush Thakur

unread,
Jul 3, 2016, 11:26:51 AM7/3/16
to django...@googlegroups.com
I recently was introduced to the concept of descriptors in Python, and it looks like fields like CharField() are descriptors. However, I find the concept of descriptors quite enigmatic, and am trying to piece together the puzzle bu asking related questions.

For now my question is: What do we gain by having these attributes on the class rather than on the instance? I mean, why can't the fields we are using in a model be defined in __init__()?

I know it's common practice to instantiate descriptors on a class-level, but I don't know why. I'm confused because one link I found (http://stackoverflow.com/questions/2714573/instance-variables-vs-class-variables-in-python) recommends putting attributes in instances than class.

I guess what I am asking is more of  a Python question than a Django one, but because Django is actually using this language feature to do something real-world, I thought of tossing the question here.

Regards,
Ankush Thakur
Reply all
Reply to author
Forward
0 new messages