Opened 14 years ago

Closed 13 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: no UI/UX: no

Description

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,

|4>s=Student()
|5>s.Meta.
s.Meta.__doc__     s.Meta.__module__  s.Meta.abstract    s.Meta.ordering

|6>s.Meta.ordering
Out[6]: ['name']

The ordering attribute from the parent abstract base class is not overwritten as described at: http://docs.djangoproject.com/en/dev/topics/db/models/#meta-and-multi-table-inheritance

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 by Ramiro Morales, 14 years ago

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 (http://paste.pocoo.org/show/292829/) 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 by Russell Keith-Magee, 13 years ago

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