Click here to Skip to main content
15,666,286 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I am trying to create a like button for my site. The code below is what I have tried to do, it did not work. Can anyone help me?
class Like(models.Model):
    user = models.ForeignKey(User)
    post = models.ForeignKey(Posts)
    created = models.DateTimeField(auto_now_add=True)
    def __unicode__(self):
        return self.user
def like(request, post_id):
    p = Posts.objects.get()
    number_of_likes = p.like_set.all().count()
    new_hipe, created = Hipe.objects.get_or_create(user=request.user, post_id=post_id)
def post_detail(request, id):
    post_details = get_object_or_404(Posts, pk=id)
    user_likes_this = post.like_set.filter(user=request.user) and True or False
    return render_to_response('posts/wall.html',locals(),context_instance=RequestContext(request))
Sergey Alexandrovich Kryukov 21-Mar-14 12:47pm    
"Did not work" is not informative.
christo4040 22-Mar-14 13:32pm    
Well, no like button out of that code. So something have to be changed, and what I meant was, do anyone see if something can be done different, so that it might would would work

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900