5

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.

Community
  • 1
  • 1
Dirk Eschler
  • 2,539
  • 1
  • 21
  • 41

1 Answers1

3

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.

Chris Pratt
  • 232,153
  • 36
  • 385
  • 444