Re: Model Meta inheriting ordering from abstract models

2016-02-09 Thread Podrigal, Aron
I see this was the intention from the very beginning as documented here
[1], but wasn't my initial take. I guess it is debatable. In any case
updating the documentation to clarify it would be helpful.


[1]
https://github.com/django/django/blob/0c20e88e65b8c2b1d097510ee2d7cfe6b2cf9b97/tests/modeltests/model_inheritance/models.py#L17-L101

On Tue, Feb 9, 2016 at 10:29 AM, Tim Graham  wrote:

> Did you try looking through git blame and old tickets to find the reason
> for it? The issue is raised on https://code.djangoproject.com/ticket/11078
> .
>
>
> On Monday, February 8, 2016 at 11:19:02 PM UTC-5, Aron Podrigal wrote:
>>
>> 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
>> -
>> '101', '1110010', '110', '1101110'   '101', '110',
>> '1100100', '1110010', '1101001', '1100111', '111', '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/83659928-1e62-469b-adb4-09dca6e15b6b%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Aron Podrigal
-
'101', '1110010', '110', '1101110'   '101', '110',
'1100100', '1110010', '1101001', '1100111', '111', '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.googl

Re: Model Meta inheriting ordering from abstract models

2016-02-09 Thread Tim Graham
Did you try looking through git blame and old tickets to find the reason 
for it? The issue is raised on https://code.djangoproject.com/ticket/11078.

On Monday, February 8, 2016 at 11:19:02 PM UTC-5, Aron Podrigal wrote:
>
> 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
> -
> '101', '1110010', '110', '1101110'   '101', '110', 
> '1100100', '1110010', '1101001', '1100111', '111', '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/83659928-1e62-469b-adb4-09dca6e15b6b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Model Meta inheriting ordering from abstract models

2016-02-08 Thread Podrigal, Aron
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
-
'101', '1110010', '110', '1101110'   '101', '110',
'1100100', '1110010', '1101001', '1100111', '111', '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.