Opened 8 years ago

Closed 7 years ago

#14701 closed (worksforme)

Meta attributes from abstract class

Reported by: Joe Owned by: nobody
Component: Database layer (models, ORM) Version: 1.2
Severity: Keywords: meta
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


class CommonInfo(models.Model):
    name = models.IntegerField(default=1)
    class Meta:
        abstract = True
        ordering = ['name']

class Student(CommonInfo):
    class Meta(CommonInfo.Meta):
        db_table = 'student_info'
        ordering = []

When instantiating Student as s,

s.Meta.__doc__     s.Meta.__module__  s.Meta.abstract    s.Meta.ordering

Out[6]: ['name']

The ordering attribute from the parent abstract base class is not overwritten as described at:

I may understand this behavior wrong, but i'd expect to be able to override the ordering attribute or clear it entirely (ordering=[]). Is this working as designed or is this an issue?

Change History (2)

comment:1 Changed 8 years ago by Ramiro Morales

Why are you trying to know the value of ordering in a Student instance?. Have you tried to see if the ordering in that model works like you expect (no ordering by the name field)? or did you assume it would fail and stopped after seeing the ipython introspection output?. From my tests ( things are working correctly.

I'd like to close this ticket because you shouldn't be examining Model.Meta nor model_instance.Meta at all.
Also, even using ._meta isn't correct because it isn't a documented API and I think model_instance._meta is an implementation wart.

But first I'd like to know what were you trying to achieve that lead you to examine the ordering value like you are doing.

Also, perhaps we could document better the fact that [] value has a special meaning to the ordering attribute.

comment:2 Changed 7 years ago by Russell Keith-Magee

Resolution: worksforme
Status: newclosed
Note: See TracTickets for help on using tickets.
Back to Top