#14705: Model Field Order not influenced by MRO of superclasses
---------------------------+------------------------------------------------
Reporter: vanschelven | Owner: nobody
Status: new | Milestone:
Component: Uncategorized | Version: 1.2
Keywords: | Stage: Unreviewed
Has_patch: 0 |
---------------------------+------------------------------------------------
Looking at the two definitions below,
{{{
class OneTwo(AbstractModelOne, AbstractModelTwo):
pass
class TwoOne(AbstractModelTwo, AbstractModelOne):
pass
}}}
one (I?) would expect the order of the fields in the second definition to
be the opposite of the order in the first one. (Since the base classes are
referenced in the opposite order). This is, however, not the case.
Django only uses creation_counter to determine the order of the fields.
Therefor the actual field order is determined by the order in which the
containing abstract classes are evaluated (i.e. their python code is
read). If these classes come from multiple sources (apps) the field order
may end up to be pretty much random (though deterministic).
The general use case is heavy use of abstract models to mix in information
from various sources into actual models. In real apps the two above models
are not very likely, but being able to have control over the field order
(other than placing the abstract models in a certain order) is important.
I make heavy use abstract models to be able to make my apps reusable. The
above situation is an important roadblock to efficient use.
A patch with a failing test is attached.
Haven't yet been able to fix this in a non-intrusive way.
I would be very much obliged if someone can come up with a solution.
--
Ticket URL: <http://code.djangoproject.com/ticket/14705>
Django <http://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.