通过模板标签Django

时间:2016-11-01 01:17:33

标签: python django

我正在使用模板标签来检查用户是否先前在Feed中显示了问题,以便向他展示喜欢"红心" img或者不是。我发送用户配置文件和问题的pk作为函数的参数,我想知道该用户配置文件是否是喜欢该问题的用户配置文件之一。我该如何以正确的方式实现它?

这是我的模板代码

from django import template
from blog.models import UserProfile
from blog.models import Question
register = template.Library()

def likecheck(theuser, question_pk):
    question_object = Question.objects.get(pk=question_pk)
    # just rude logic of what I seek
    # if theuser in question_object.who_liked:
    #   return true
    # else:
    #   return false

register.filter('likecheck', like check)

models.py中的相关课程:

class Question(models.Model):
    who_liked = models.ManyToManyField('UserProfile',    
    related_name='who_liked_QUESTION', blank=True, null=True)

1 个答案:

答案 0 :(得分:0)

我认为您在伪代码question_object.who_liked的末尾错过了$ docker run -v $(pwd):/files alpine-pdftk --help