Opened 5 months ago
Last modified 4 months ago
#35827 new New feature
Model subclass with __init_subclass__ doesn't get correct _meta instance — at Version 3
Description (last modified by ) ¶
When defining and using a model mixin like so:
class ModelMixin(Model): class Meta: abstract = True def __init_subclass__(cls) -> None: super().__init_subclass__() breakpoint() cls._my_setup_func() class TestModel(ModelMixin): name = models.CharField(max_length=100)
The init_subclass call will be first called when the class is created here:
https://github.com/django/django/blob/main/django/db/models/base.py#L120
However the meta is attached here:
https://github.com/django/django/blob/main/django/db/models/base.py#L143
So during the init_subclass call you will have the superclass' meta object if you try to access it.
According to the ticket's flags, the next step(s) to move this issue forward are:
Unknown. The Someday/Maybe triage stage is used to keep track of high-level ideas or long term feature requests.
It could be an issue that's blocked until a future version of Django (if so, Keywords will contain that version number). It could also be an enhancement request that we might consider adding someday to the framework if an excellent patch is submitted.
If you're interested in contributing to the issue, raising your ideas on the Django Forum would be a great place to start.
Change History (3)
comment:1 by , 5 months ago
Description: | modified (diff) |
---|
comment:2 by , 5 months ago
Description: | modified (diff) |
---|
comment:3 by , 5 months ago
Description: | modified (diff) |
---|