Skip to content

Instantly share code, notes, and snippets.

@powellc
Created September 16, 2010 16:38
Show Gist options
  • Save powellc/582724 to your computer and use it in GitHub Desktop.
Save powellc/582724 to your computer and use it in GitHub Desktop.
diff --git a/src/adzone/managers.py b/src/adzone/managers.py
index 347e85e..271e36d 100644
--- a/src/adzone/managers.py
+++ b/src/adzone/managers.py
@@ -8,8 +8,15 @@ class AdManager(models.Manager):
Returns a random advert that belongs to the specified category and zone
"""
- try:
- ad = self.get_query_set().filter(category__slug=ad_category, zone__slug=ad_zone).order_by('?')[0]
- except IndexError:
- return None;
+ if ad_category=='':
+ try:
+ ad = self.get_query_set().filter(zone__slug=ad_zone).order_by('?')[0]
+ except IndexError:
+ return None;
+ else:
+ try:
+ ad = self.get_query_set().filter(category__slug=ad_category, zone__slug=ad_zone).order_by('?')[
+ except IndexError:
+ return None;
+
return ad
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment