为什么Django的Meta是一个老式的类? [英] Why is Django's Meta an old-style class?
本文介绍了为什么Django的Meta是一个老式的类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我注意到,在Django模型中,有一个类Meta
,它对模型做了一些额外的定义。
<我的问题是,为什么这是一个老式的类? (即不是子类化
对象
?)有这样的原因或者这只是一个自定义? 解决方案
我相信没有什么真正的原因,因为自Python 2.2以来存在新式类),并且不仅可以选择使用新式类,而且可能是一个好主意(因为所有通常的原因)。
I noticed that in Django models, there is a class Meta
which makes some additional definitions about the model.
My question is, why is this done as an old-style class? (i.e. not subclassing object
?) Is there a reason for this or is this just a custom? Could I do it as a new-style class in my projects?
解决方案
I believe that there is no real reason (including history, since new-style classes exist since Python 2.2) and that not only can you choose to use a new-style class instead, but that it would probably be a good idea for you to do so (for all the usual reasons).
这篇关于为什么Django的Meta是一个老式的类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文