为什么我不能将类Meta作为Django模型类的属性访问? [英] Why can't I access class Meta as a attribute of Django Model Class?
本文介绍了为什么我不能将类Meta作为Django模型类的属性访问?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Python中,我可以定义:
In Python I can define:
class Person(object):
name = "Easwar"
age = 35
sex = "male"
class Occupation:
name = "my_job"
然后我可以访问它
>> p = Person()
>> p.Occupation.name
>> # prints "my_job"
但是在Django中,如果我有一个内部定义了Class Meta的模型这样做
However in Django, if I have a model defined with Class Meta inside I cannot do this
>>> m = SomeDjangoModel()
>>> m.Meta
>>> # prints AttributeError!
为什么?
Django的内部Meta类与常规的Python类有什么不同?
Why is this ? How is Django's inner Meta class different from a regular Python class ?
我确实对此进行了研究,但并未提出类似的要求。
如果我错过了,请原谅。
I did research this and didnt come up with anything similar asked here. Please excuse me if I have missed it.
预先感谢您的帮助。
推荐答案
Meta属性
尝试:
SomeDjangoModel._meta
这篇关于为什么我不能将类Meta作为Django模型类的属性访问?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文