如何在HTML中显示关联ManyToManyField

问题描述

我被ManyToManyField困住了演出关系帖子

python3 / django3.1

models.py

class Post(models.Model):
    title = models.CharField(max_length=10)
    relation = models.ManyToManyField('self',blank=True)

有3个帖子

post.title = [title1,title2,title3]

title1 related [title1,title3]

index.html

{% for p in post %}

<p>{{ p.title }} </p>

<li>{{ p.relation.all|join:"," }}</li>

{% endfor post %}

结果是

title1

・title1

但是,我想展示

title1

・title1 
・title2
・title3

我的问题是如何显示{{p.relation.all}}中的所有关系?我想.all不会影响ManyToManyfileld。

感谢您的阅读。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...