ORM _meta

Import OS
 IF  the __name__ == ' __main__ ' : 
    os.environ.setdefault ( ' the DJANGO_SETTINGS_MODULE ' , ' XadminDemon.settings ' )
     Import Django 
    django.setup () 
    from app01 Import Models
     # obtain the value of app 
    RET = models.Book._meta. app_label
     Print (RET)
     # Get the name of the model 
    RET = models.Book._meta.model_name
     Print (RET)
     # get property field
    obj = models.Book._meta.get_field("title")
    ret = obj.verbose_name
    print(ret)
    obj = models.Book._meta.get_field("price")
    ret = obj.verbose_name
    print(ret)
"""
app01
book
书名
price
"""

 

Guess you like

Origin www.cnblogs.com/wt7018/p/11374559.html