Hi,

While going through the code for ModelBase I came across the following
which I was unable to get it  clear from the documentation.

A model inheriting from a concrete model does not inherit the Meta class of
its parent no matter if it has a Meta of its own. However, it does inherit
2 options, which they are: *ordering* and *get_latest_by*. Even when it has
a Meta of its own, as long as those 2 options have not been overridden
explicitly. By contrast, inheriting from an abstract model inherits the
Meta class of the abstract model when it does not have a Meta class of its
own. What I find unclear, is, when a model inherits from an abstract model
which defines meta.ordering, if the child model also has its own Meta
class, it does not inherit the ordering option from it's parent.

Is this by design


class AbstractModelWithOrdering(models.Model):
    name = models.CharField(max_length=255)

    class Meta:
        ordering = ['-name']
        abstract = True


class ExtendAbstractModelWithOrdering(AbstractModelWithOrdering):
    class Meta:
        db_table = 'extended_abstract_model'


class ConcreteModelWithOrdering(models.Model):
    name = models.CharField(max_length=255)

    class Meta:
        ordering = ['-name']


class ExtendConcreteModelWithOrdering(ConcreteModelWithOrdering):
    class Meta:
        db_table = 'extended_concrete_model'




class InheritedOrderingTests(SimpleTestCase):
    def test_inheriting_from_abstract_with_meta_inherits_ordering(self):
        self.assertEqual(ExtendAbstractModelWithOrdering._meta.ordering,
['-name'])

    def test_inheriting_from_concrete_with_meta_inherits_ordering(self):
        self.assertEqual(ExtendConcreteModelWithOrdering._meta.ordering,
['-name'])



======================================================================
FAIL: test_inheriting_from_abstract_with_meta_inherits_ordering
(model_meta.tests.InheritedOrderingTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/aron/django/django_repo/tests/model_meta/tests.py", line 280,
in test_inheriting_from_abstract_with_meta_inherits_ordering
    self.assertEqual(ExtendAbstractModelWithOrdering._meta.ordering,
['-name'])
AssertionError: Lists differ: [] != ['-name']

Second list contains 1 additional elements.
First extra element 0:
-name

- []
+ ['-name']

----------------------------------------------------------------------
Ran 2 tests in 0.001s

FAILED (failures=1)


-- 
Aron Podrigal
-
'1000001', '1110010', '1101111', '1101110'   '1010000', '1101111',
'1100100', '1110010', '1101001', '1100111', '1100001', '1101100'

P: '2b', '31', '33', '34', '37', '34', '35', '38', '36', '30', '39', '39'

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/CANJp-yiad%2BOhHQ06giAoaFWEBthkuj4%3DhjUYGHOhpfUx9o9hbA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to