I was going 
through 
https://docs.djangoproject.com/en/1.9/topics/db/managers/#custom-managers-and-model-inheritance
 
regarding custom managers and I decided to do some tests. Here are my 
models:

from django.db import models


class CustomManager(models.Manager):

    use_for_related_fields = True


class ExtraManager(models.Manager):
    use_for_related_fields = True


class AnotherManager(models.Manager):
    use_for_related_fields = True


class A(models.Model):

    objects = CustomManager()

    all_objects = AnotherManager()

    class Meta:
        abstract = True


class B(A):
    pass


class C(A):
    objects = ExtraManager()


class D(C):
    pass


class E(A):
    all_objects = AnotherManager()
    objects = ExtraManager()


class F(E):
    pass


Here are the results of few code executions:

In [1]: from app.models import *

In [2]: F.objects
Out[2]: <django.db.models.manager.Manager at 0x7f160dfe8e48>

In [3]: D.objects
Out[3]: <app.models.ExtraManager at 0x7f160dfe80b8>

In [4]: D._default_manager
Out[4]: <app.models.AnotherManager at 0x7f160dfe8978>

In [5]: F._de
F._default_manager  F._deferred         

In [5]: F._default_manager
Out[5]: <django.db.models.manager.Manager at 0x7f160dfe8e48>

In [6]: F.all_objects
Out[6]: <app.models.AnotherManager at 0x7f160dfe87f0>



Here I have few queries:
- How come AnotherManager is default Manage for D? It is neither default 
manager for C and neither it is first Manager in A.
 
- Why D.objects is ExtraManager (from C objects) but F.objects is default 
Django Manager

Someone please help to understand theses. Thanks!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/45df67aa-3d06-4ef5-a736-42c5ff773228%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to