qrurls/models.py
changeset 81 3a2fdc820c41
parent 80 3aaac91a6654
child 82 6442e5c97b48
--- a/qrurls/models.py	Sat Sep 07 15:35:56 2013 +0300
+++ b/qrurls/models.py	Sat Sep 07 15:38:24 2013 +0300
@@ -183,7 +183,7 @@
         ordering = ['published']
 
     @classmethod
-    def search (cls, shorturl=None, shorturl_id=None, item_id=None, related=()) :
+    def search (cls, shorturl=None, item_id=None, related=()) :
         """
             Return the URLItem for a given shorturl, either the given specific one,
             or the latest, from the database.
@@ -193,13 +193,13 @@
         # JOIN against shorturl, urlimage
         url_item = cls.objects.select_related(*related)
 
-        if shorturl:
-            url_item = url_item.filter(shorturl__shorturl=shorturl)
-        elif shorturl_id:
-            shorturl_id = int(shorturl_id)
+        if not shorturl:
+            raise cls.DoesNotExist()
+        elif shorturl.isdigit():
+            shorturl_id = int(shorturl)
             url_item = url_item.filter(shorturl__id=shorturl_id)
         else:
-            raise cls.DoesNotExist()
+            url_item = url_item.filter(shorturl__shorturl=shorturl)
         
         # match for published items
         now = timezone.now()