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
If you want to make a manager default and that manager object is not defined first then you can define it as default manager by setting default_manager_name of Meta class equal to that object name. You can do anything you want with custom managers.
Custom managers. You can use a custom Manager in a particular model by extending the base Manager class and instantiating your custom Manager in your model. There are two reasons you might want to customize a Manager : to add extra Manager methods, and/or to modify the initial QuerySet the Manager returns.
Rahul Mishra. Django Model Manager is the interface through which database query operations are provided to Django models. objects is the default model manager and each model needs to have at least one model manager. Let's see a few use-cases when we can use model managers and when to use custom model managers.
The model managers is a major tool of Django's ORM that developers use to interact with the database. Fundamentally a manager is a Python class that inherits from the Manager class defined in Django's db. models package. According to Django Docs, at least one Manager exists for every model in a Django application.
I have found only this solution:
instance.entry_set(manager='custom_manager')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With