Skip to content

Instantly share code, notes, and snippets.

@fitoria
Created August 9, 2009 04:33
Show Gist options
  • Save fitoria/164627 to your computer and use it in GitHub Desktop.
Save fitoria/164627 to your computer and use it in GitHub Desktop.
##current version: fails when the user is anonymous.
favorited = question.has_favorite_by_user(request.user)
question_vote = question.votes.select_related().filter(user=request.user)
if question_vote is not None and question_vote.count() > 0:
question_vote = question_vote[0]
##modified by me:
favorited = question.has_favorite_by_user(request.user)
if not request.user.is_anonymous():
question_vote = question.votes.select_related().filter(user=request.user)
else:
question_vote = None #is this correct??
if question_vote is not None and question_vote.count() > 0:
question_vote = question_vote[0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment