Code

Opened 3 years ago

Closed 3 years ago

#14701 closed (worksforme)

Meta attributes from abstract class

Reported by: sneakywombat 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:

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?

Attachments (0)

Change History (2)

comment:1 Changed 3 years ago by ramiro

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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 Changed 3 years ago by russellm

  • Resolution set to worksforme
  • Status changed from new to closed

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.