title: How to use custom manager with related objects?
body: <p>I have a custom manager. I want to use it for related objects. I found   <a href="https://docs.djangoproject.com/en/dev/topics/db/managers/#controlling-automatic-manager-typesin">use_for_related_fields</a> in docs. But it does not work the way I used it:</p>
  
  <pre><code>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().randomize()
  </code></pre>
  
  <p>I used it for one model:</p>
  
  <pre><code>&gt;&gt;&gt; post = PostPages.default_manager.filter(image_gallery__isnull=False).distinct().randomize()
  </code></pre>
  
  <p>And tried to do the same with m2m related object:</p>
  
  <pre><code>&gt;&gt;&gt; post.image_gallery.randomize()
  </code></pre>
  
  <p>Got an error: </p>
  
  <pre><code>AttributeError: 'ManyRelatedManager' object has no attribute 'randomize'
  </code></pre>
  
  <p>Is it possible to use a custom manager in the way I did it? If so, how do you make it work?</p>
  
  <h1>Edit</h1>
  
  <p>My models:</p>
  
  <pre><code>class ShivaImage(models.Model, ImageResizing):
      image = models.ImageField(upload_to='img')
      slide_show = models.BooleanField() 
      title = models.CharField(max_length=100)
      text = models.TextField(max_length=400)
      ordering = models.IntegerField(blank=True, null=True)
  
      objects = RandomManager()
  
  
  class PostPages(models.Model):
      image_gallery = models.ManyToManyField(ShivaImage, blank=True,
                                         related_name='gallery',)
      # all the other fields... 
  
      objects = RandomManager()
  </code></pre>