def get_random_ad(self, ad_zone, ad_category=None):
        """
        Returns a random advert that belongs for the specified ``ad_category``
        and ``ad_zone``.
        If ``ad_category`` is None, the ad will be category independent.
        """
        qs = self.get_queryset().filter(start_showing__lte=now(),
                                         stop_showing__gte=now(),
                                         zone__slug=ad_zone,
                                         sites=Site.objects.get_current().pk
                                         ).select_related('textad',
                                                          'bannerad')
        if ad_category:
            qs = qs.filter(category__slug=ad_category)
        try:
            ad = qs.order_by('?')[0]
        except __HOLE__:
            return None
        return ad
dataset/ETHPy150Open andrewebdev/django-adzone/adzone/managers.py/AdManager.get_random_ad