Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is the inner Meta class of a Django model restricted?

Is there a good reason why you can't add custom attributes to the inner Meta class of a Django model? The only one i can think of is to catch misconfigurations.

This thread shows how it can be worked around, but i'm wondering if there are any other reasons for this restriction.

like image 317
Dirk Eschler Avatar asked Oct 24 '22 06:10

Dirk Eschler


1 Answers

Options, the class that processes Meta, and actually adds the _meta attribute to the model, runs through the attributes of Meta in a loop and uses setattr on itself to transfer the data. That process would fail if there's an attribute on Meta that doesn't exist on Options.

Now, there might be other reasons, but that's the only one I can glean from the source.

like image 165
Chris Pratt Avatar answered Oct 27 '22 11:10

Chris Pratt