What I want to do is simple I want to update the count variable of the object every time my view function is called.
My models is like this:
class Url(models.Model):
#some vars here
count=0
def __unicode__(self):
return self.urlx
def incr(self):
self.count+=1
and my view code is like this
@transaction.autocommit
def redirect(request,key):
if(key):
key='/'+key
try:
ob=Url.objects.get(urlx=key)
ob.incr() #not working
ob.save() #not working
return HttpResponseRedirect(ob.url)
val=ob.count
except Url.DoesNotExist:
key="Sorry! couldn't find that url"
return render_to_response('redir.html',{},context_instance=RequestContext(request))
I am sure I am overlooking something here, or is this not the correct way to do this?