[Django] #29354: ordering inherited from abstract superclass does not get applied to admin inlines

7 views
Skip to first unread message

Django

unread,
Apr 24, 2018, 5:43:05 AM4/24/18
to django-...@googlegroups.com
#29354: ordering inherited from abstract superclass does not get applied to admin
inlines
-------------------------------------+-------------------------------------
Reporter: Moritz | Owner: nobody
Pfeiffer |
Type: Bug | Status: new
Component: Database | Version: 1.11
layer (models, ORM) | Keywords: ordering
Severity: Normal | inheritance abstract meta
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
The attached project illustrates a problem where ```Meta.ordering```
inherited from an abstract superclass does not get applied to admin
inlines.

Suppose we have the following models:

{{{#!python
from django.db import models


class Orderable(models.Model):
sort_order = models.IntegerField(null=True, blank=True)

class Meta:
abstract = True
ordering = ['sort_order']


class Foo(models.Model):
name = models.CharField(max_length=50)

def __str__(self):
return self.name

class Meta:
verbose_name = 'foo'
verbose_name_plural = 'foos'


class Bar(Orderable, models.Model):
foo = models.ForeignKey(Foo, blank=True, null=True,
on_delete=models.CASCADE)
name = models.CharField(max_length=50)

def __str__(self):
return '{}-{}'.format(self.name, self.sort_order)

class Meta:
verbose_name = 'bar'
verbose_name_plural = 'bars'
# ordering = ['sort_order'] # needs to be explicitly set to
effect admin inline ordering
}}}

and the following admin definition:
{{{#!python
from django.contrib import admin
from metainheritance.models import Foo, Bar


class BarInline(admin.StackedInline):
model = Bar
fields = ['foo', 'name', 'sort_order']
extra = 0


class FooAdmin(admin.ModelAdmin):
inlines = [BarInline]

admin.site.register(Foo, FooAdmin)


}}}

Then BarInline objects in the admin interface will only be ordered by
```sort_order``` if it is explicitly defined on Bar.Meta.

In the attached project, there is a custome management command ```python
manage.py create_data``` to initialize the database.

--
Ticket URL: <https://code.djangoproject.com/ticket/29354>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Apr 24, 2018, 5:43:57 AM4/24/18
to django-...@googlegroups.com
#29354: ordering inherited from abstract superclass does not get applied to admin
inlines
-------------------------------------+-------------------------------------
Reporter: Moritz Pfeiffer | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.11
(models, ORM) |
Severity: Normal | Resolution:
Keywords: ordering | Triage Stage:
inheritance abstract meta | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Moritz Pfeiffer):

* Attachment "meta_inheritance_test.zip" added.

Test project that illustrates the problem

Django

unread,
Apr 24, 2018, 6:24:44 AM4/24/18
to django-...@googlegroups.com
#29354: ordering inherited from abstract superclass does not get applied to admin
inlines
-------------------------------------+-------------------------------------
Reporter: Moritz Pfeiffer | Owner: nobody
Type: Bug | Status: new

Component: Database layer | Version: 1.11
(models, ORM) |
Severity: Normal | Resolution:
Keywords: ordering | Triage Stage:
inheritance abstract meta | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):

* cc: felixxm (added)


Comment:

IMO `Bar.Meta` should inherit from `Orderable.Meta` (please see
https://docs.djangoproject.com/en/2.0/topics/db/models/#meta-inheritance).

--
Ticket URL: <https://code.djangoproject.com/ticket/29354#comment:1>

Django

unread,
Apr 24, 2018, 11:34:29 AM4/24/18
to django-...@googlegroups.com
#29354: ordering inherited from abstract superclass does not get applied to admin
inlines
-------------------------------------+-------------------------------------
Reporter: Moritz Pfeiffer | Owner: nobody
Type: Bug | Status: closed

Component: Database layer | Version: 1.11
(models, ORM) |
Severity: Normal | Resolution: invalid

Keywords: ordering | Triage Stage:
inheritance abstract meta | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* status: new => closed
* resolution: => invalid


Comment:

That analysis looks correct to me.

--
Ticket URL: <https://code.djangoproject.com/ticket/29354#comment:2>

Reply all
Reply to author
Forward
0 new messages