How to use custom manager with related objects?
问题 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 RandomQueryset(models.query.QuerySet): def randomize(self): count = self.count() random_index = random.randint(0, count - 1) return self.all()[random_index] class RandomManager(models.Manager): use_for_related_fields = True def get_query_set(self): return RandomQueryset(self.model, using=self._db) def randomize(self): return self.get_query_set()