def get(self, _): urlid = utoi(self.short) try: shorturl = URL.objects.get(id=urlid) shorturl.clicks += 1 shorturl.save() except (URL.DoesNotExist, OverflowError): # OverflowError is odd, see raise Http404("%s not in database" % self.short) return HttpResponseRedirect(shorturl.url)
def dispatch(self, request, *args, **kwargs): self.pk = utoi(kwargs.pop('short')) return super(Results, self).dispatch(request, *args, **kwargs)