I have class:
class Image(models.Model):
title = models.CharField(max_length=100)
imgFile1 = models.FileField(upload_to='%Y/%m/%d')
vote1 = models.IntegerField(default=0)
trofeum1 = models.IntegerField(default=0)
imgFile2 = models.FileField(upload_to='%Y/%m/%d')
vote2 = models.IntegerField(default=0)
trofeum2 = models.IntegerField(default=0)
home = models.IntegerField(default=0)
and function in views.py:
def vote1(request,i_id=0):
imgId = str(i_id)
try:
if (request.session[imgId] == True):
return HttpResponseRedirect(reverse('app.views.err'))
except Exception:
request.session[imgId] = True
try:
image = Image.objects.get(pk=i_id)
except Exception:
image = None
image.vote1+=1
image.save()
if image.vote1 == 5:
image.trofeum1 += 1
image.trofeum2 = 0
image.vote1 = 0
image.vote2 = 0
image.imgFile2 = None
image.save()
return HttpResponseRedirect('app.views.index'))
So it updates certain object in my database after clicking some link on my site, but I dont want to redirect after that, just want to change object in my database – CLICK->UPDATE->NOTHING ELSE. Do you know any solutions to avoid error:The view app.views.vote1 didn’t return an HttpResponse object or any other way to do that?
I redirect to the same page but after that I’m on the top of the page – I want to be on the same place where I clicked the link.
Try to do the same thing with Ajax. It will do that.