Meta inheritance across abstract base class

32 views
Skip to first unread message

Torsten Bronger

unread,
Nov 24, 2014, 8:19:50 AM11/24/14
to django...@googlegroups.com
Hallöchen!

I have the following model structure:

class A(models.Model):
...
class Meta:
ordering = ["timestamp"]
get_latest_by = "timestamp"

class B(A):
class Meta(A.Meta):
abstract = True

class C(B):
...

Then, class C doesn't haven ordering or get_latest_by set. Is this
expected behaviour? Then, I would simply re-define them in B.

Tschö,
Torsten.

--
Torsten Bronger Jabber ID: torsten...@jabber.rwth-aachen.de
or http://bronger-jmp.appspot.com

Collin Anderson

unread,
Nov 25, 2014, 8:58:43 AM11/25/14
to django...@googlegroups.com
Hi,

If you define a new class Meta on C, then it will _replace_ the previous class Meta. You can, however have class Meta inherit other class Meta.
class Student(CommonInfo):
   
# ...
   
class Meta(CommonInfo.Meta):
        db_table
= 'student_info'


Collin

Torsten Bronger

unread,
Nov 25, 2014, 9:27:31 AM11/25/14
to django...@googlegroups.com
Hallöchen!

Collin Anderson writes:

> If you define a new class Meta on C, then it will _replace_ the
> previous class Meta. [...]

I indeed have a Meta class in C but it is derived from the upstream
Meta class. The inheritance chain in my Meta's is uninterrupted.

Collin Anderson

unread,
Nov 26, 2014, 9:01:07 AM11/26/14
to django...@googlegroups.com
Hi,

Ohh. Yup. I didn't read that carefully enough. That behavior doesn't seem expected to me. Expecially considering this sentence:

"if the child does not specify an ordering attribute or a get_latest_by attribute, it will inherit these from its parent."

Collin
Reply all
Reply to author
Forward
0 new messages