How do I turn this into a function that can be called from a template?
>>> var1 = coremodels.Recommendation.objects.get(title="test5")
>>> user = User.objects.get(username='admin') // should get self.request.user
>>> var1.vote.exists(user)
Current Attempt:
I currently have it in models.py but getting error global name 'user' not defined:
class Recommendation(models.Model):
user = models.ForeignKey(User)
def check_user_voted(self):
user_voted = self.votes.exists(user)
return user_voted
This is the html request:
{% if recommendation.check_user_voted %}
<p>User Voted</p>
{% endif %}