#16646: Only first meta inner class inherited with multiple abstract base
models.
---------------------+----------------------------------------------
Reporter: varikin | Owner: nobody
Type: Bug | Status: new
Milestone: | Component: Database layer (models, ORM)
Version: 1.3 | Severity: Normal
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Easy pickings: 0
UI/UX: 0 |
---------------------+----------------------------------------------
Code shows this better:
app.models.py
{{{
from django.db import models
class FirstMixin(models.Model):
name = models.CharField(max_length=100)
class Meta:
abstract = True
class SecondMixin(models.Model):
order = models.PositiveIntegerField()
class Meta:
abstract = True
ordering = ['order']
class Concrete(FirstMixin, SecondMixin):
published = models.BooleanField()
}}}
Ordering is set on the Concrete instances:
{{{
>>> from red.models import Concrete
>>> c = Concrete()
>>> c._meta.ordering
[]
}}}
If instead concrete is defined with
{{{
class Concrete(SecondMixin, FirstMixin):
published = models.BooleanField()
}}}
Notice that SecondMixin is the first class that Concrete subclasses
instead of FirstMixin. This results in
{{{
>>> c = Concrete()
>>> c._meta.ordering
['order']
}}}
It is very unintuitive and in my opinion incorrect. The order of which
classes to inherit from shouldn't prevent inheriting the Meta inner class
as well. This could cause hard to find bugs, such as why 'ordering' is not
correct or why two different concrete classes have different meta settings
while having the same parent classes.
The other way to address this is like so:
{{{
class Concrete(FirstMixin, SecondMixin):
published = models.BooleanField()
class Meta(SecondMixin.Meta):
pass
}}}
This is more explicit, but would a developer think this has to be done
until they ran into this issue? Also, I think this is the only way to
possibly get Meta options from multiple parent classes by having class
Meta(SecondMixin.Meta, FirstMixin.Meta).
--
Ticket URL: <https://code.djangoproject.com/ticket/16646>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.