Django models & Python class attributes

后端 未结 4 1714
再見小時候
再見小時候 2021-01-12 06:09

The tutorial on the django website shows this code for the models:

from django.db import models

class Poll(models.Model):
    question = models.CharField(ma         


        
4条回答
  •  再見小時候
    2021-01-12 06:32

    Have a look at the Model class under django/db/models.py. There the class attributes are turned to instance attributes via something like

    setattr(self, field.attname, val)
    

    One might recommend the whole file (ModelBase and Model class) as an excellent hands-on example on metaclasses.

提交回复
热议问题