Python Django:确定模板中的多个关系

Python Django:确定模板中的多个关系,python,django,filtering,django-templates,Python,Django,Filtering,Django Templates,我的ForeignKey关系设置如下: class WatchList(models.Model): user = models.ForeignKey(User) class Thing(models.Model) watchlist = models.ForeignKey(WatchList, null=True, blank=True) {% if thing.watchlist.user != request.user %} Something {% else

我的
ForeignKey
关系设置如下:

class WatchList(models.Model):
    user = models.ForeignKey(User)

class Thing(models.Model)
    watchlist = models.ForeignKey(WatchList, null=True, blank=True)
{% if thing.watchlist.user != request.user %}
     Something
{% else %}
     Nothing
{% endif %}
这允许我有条件地在模板中显示不同的消息,如下所示:

class WatchList(models.Model):
    user = models.ForeignKey(User)

class Thing(models.Model)
    watchlist = models.ForeignKey(WatchList, null=True, blank=True)
{% if thing.watchlist.user != request.user %}
     Something
{% else %}
     Nothing
{% endif %}

但是,现在我已将我的关系从
ForeignKey
更改为
ManyToManyField
,这种模板内过滤不再有效:

class WatchList(models.Model):
    user = models.ForeignKey(User)

class Thing(models.Model)
    watchlist = models.ManyToManyField(WatchList)
在模板中尝试这种类型的templatetag筛选会显示一个
属性错误:“ManyRelatedManager”对象没有属性“user”

如果
{%if thing.watchlist.user!=request.user%}

尝试替换,如何筛选模板中具有多个关系的对象,以便显示不同的消息

{% if thing.watchlist.user != request.user %}

因为现在你有了一个m2m关系,所以用户列表不仅仅是一个。 因此,
.all
将返回用户列表,而不是m2m对象(不确定它是对象,不知道如何调用它)