Ram Rachum
Ram Rachum

Reputation: 88578

Why is Django's Meta an old-style class?

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?

Upvotes: 19

Views: 1782

Answers (2)

Carl Meyer
Carl Meyer

Reputation: 126591

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.

Upvotes: 9

Alex Martelli
Alex Martelli

Reputation: 881705

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).

Upvotes: 16

Related Questions