6

I want to get the related object references and I want to use a custom manager.

I see there has been already a question about it, but its not open anymore. So im creating a new one Edit: And its outdated.

This is pretty much what im trying to do: Related objects reference with custom manager

b.entry_set.all() # This will use the default Manager
b.custom_manager.entry_set.all() # This should use my custom model manager

I see the ticket is closed but i havent found a solution to it yet. https://code.djangoproject.com/ticket/3871

Im using django 1.6.5

Community
  • 1
  • 1
Agey
  • 891
  • 8
  • 17

2 Answers2

12

I have found only this solution:

instance.entry_set(manager='custom_manager')
Sławek Kabik
  • 669
  • 8
  • 13
  • I tried that but all i got was this: `TypeError: 'RelatedManager' object is not callable` You might be using a different django version maybe? – Agey Dec 15 '14 at 09:24
  • 1
    Maybe.. It's for django 1.7 – Sławek Kabik Dec 15 '14 at 12:35
  • This works for me but I would like to know if there is a section in the documentation for this? – Artisan Jan 24 '20 at 15:52
  • 2
    @Omar this is now covered in the docs for [using a custom reverse manager](https://docs.djangoproject.com/en/3.1/topics/db/queries/#using-a-custom-reverse-manager) – Alasdair Feb 03 '21 at 17:52
  • Working on Django 3: Use it as: custom_manager_result_qs = some_model.related_name(manager='my_manager').filter(...). This way you can use multiple managers to fetch related objects. – Kundan Kumar Oct 20 '21 at 11:21
0

In Django 1.8, you can override the _default_manager attribute, which is used for reverse relationships (and direct queries via objects).

TeknasVaruas
  • 1,480
  • 3
  • 15
  • 28