code: def get_related_galleries(gallery, count=5):
      
      # just get the first cat. If they assigned to more than one, tough
      try:
          cat = gallery.sections.all()[0]
          related = cat.gallery_categories.filter(published=True).exclude(id=gallery.id).order_by('-id')[:count]
      except:
          related = None
      return {'related': related, 'MEDIA_URL': settings.MEDIA_URL}
docs: Gets latest related galleries from same section as originating gallery.
  
      Count defaults to five but can be overridden.
  
      Usage: {% get_related_galleries gallery <10> %}