How to use custom manager with related objects? How to use custom manager with related objects? django django

How to use custom manager with related objects?


For completeness of the topic, Django 1.7 (finally) supports using a custom reverse manager, so you can do something like that (just copying from the django docs):

from django.db import modelsclass Entry(models.Model):    objects = models.Manager()  # Default Manager    entries = EntryManager()    # Custom Managerb = Blog.objects.get(id=1)b.entry_set(manager='entries').all()


Setting use_for_related_fields to True on the manager will make it available on all relations that point to the model on which you defined this manager as the default manager. This is documented here

class MyManager(models.Manager):    use_for_related_fields = True    # ...

I suppose you have it only enabled on your PostPages model, not on your Gallery model (or whatever the model is called that is referenced through post_image_gallery). If you want to have additionally functionality on this realtion manager you need to add a custom default manager with use_for_related_fields = True to your Gallery model!