How to use custom manager with related objects?

前端 未结 4 1612
无人共我
无人共我 2020-12-02 20:08

I have a custom manager. I want to use it for related objects. I found use_for_related_fields in docs. But it does not work the way I used it:

class Random         


        
4条回答
  •  一整个雨季
    2020-12-02 20:37

    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!

提交回复
热议问题