I am trying to create a basic up down voting system for anonymous users that do not need to be signed in so any visitor can push once and a vote is entered. Obviously we have to restrict people to one vote. After some research and no luck with the djangoratings module, I found that evercookie for django is the most promising approach to this ability. However, I need a bit of help writing the part of the code that compares the evercookies of the votes currently cast on an object with a possible incoming code. I have a lot of the other things figured out I think.
My basic django model object at its core is a submitted URL with an IntegerField for keeping track of the likes:
class newlink(models.Model):
linktag = models.ForeignKey(‘pagename’) #the page the link belongs in
linkcomment = models.CharField(max_length=128) #comment to go along with post
postlinkdate = models.DateTimeField(auto_now_add=True) #submission datestamp
url = models.URLField(max_length = 1024)
linklikescounter = models.IntegerField(null=False, default=0) #this is what will be changed up or down per vote
# Do I need another field(s) in this model to store evercookie data? Or maybe a new "likevote" class that has a ForeignKey relationship to the newlink class?
def __unicode__(self):
return self.url
I have this simple button/form in my template:
<form action="/{{pagename_param}}" method="post">
{% csrf_token %}
<input type="hidden" name="linkset_likeid" value="{{ linkset.id }}">
<input type="submit" class="btn" value="like" name="linklikebtn"/>
</form>
And my views for getting this going:
if (request.POST.get('linklikebtn')):
linkid = request.POST[‘linkset_likeid’] #retrieve the ID from the form
url = newlink.objects.get(id=commentid) #get an instance of the desired url
url.linklikescounter += 1 #increase the IntegerField by 1
url.save() #save to the db