Support inheritance for model option classes
|Reported by:||miracle2k||Owned by:||nobody|
|Cc:||Triage Stage:||Fixed on a branch|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
This currently is not possible:
class BaseMeta(object): app_label = "myapp" class Company(models.Model): class Meta(BaseMeta): pass
The reason is that db.models.options.Options.contribute_to_class() uses __dict__ to determine which attributes have been given. It attempts to delete from __dict__, which apparently is not allowed for new-style classes, but __dict__ will not include attributes of superclasses anyway.
I attached a simple patch that uses dir() instead - if been using it for a while and there don't seem to be any problems.
Note that the patch will *not* allow custom meta attributes by prefixing them with __:
metakritik.site: 'class Meta' got invalid attribute(s): _BaseMeta__myopt
Change History (3)
comment:1 Changed 9 years ago by
|Patch needs improvement:||unset|
|Triage Stage:||Unreviewed → Fixed on a branch|