2👍
This is really too complex to answer in a question here. The quick answer is, it’s all done with metaclasses, but for the full explanation you should read Marty Alchin’s book Pro Django.
The point is that you don’t want self.title
, for example, to be a field instance: you want it to be whatever the value of the title is. So, (simplifying quite a bit) when the model instance is constructed from the database, the metaclass goes through the class-level Field attributes, and for each one it sets an instance-level attribute to the value of the db column. On save, of course, it does the reverse.
0👍
class in python and how model in django are defined is different. The definition of model in django just use the syntax of python as a descriptive language for field and database related informations, then django introspect the class for extract this informations. But for the rest it’s a normal python class, you can define method etc …