Django - Accessing model from django.contrib's User class via ManyToManyKey
I am making a Hacker News Clone in Django as taught in a Tuts+ Course [Git
Repo]
In views.py file, for vote view, I tried using this code to increase
security by checking if user has liked the story already.
@login_required
def vote(request):
story = get_object_or_404(Story, pk=request.POST.get('story'))
user = request.user
if user.is_authenticated() and story not in user.liked_stories:
story.points += 1
story.save()
user.liked_stories.add(story)
user.save()
return HttpResponse()
But it gives me this Error:
NameError: global name 'liked_stories' is not defined
[18/Aug/2013 19:26:43] "POST /vote/ HTTP/1.1" 500 11148
I am able to use user.liked_stories in index view so why not in vote view?
No comments:
Post a Comment