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 projec开发者_开发技巧ts?
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).
Since class Meta is never anything but a simple namespace container, there is zero advantage to subclassing object; just eight extra characters to type. Won't hurt anything to do so if you feel like it, though.
精彩评论