在Django的模板中使用m2m

关键字: django, many-to-many, template, m2m

最近在写自己的blog系统,自然就想到加上了tags。在我的数据库中,把tag扔在一个单独的表Tags中,然后在Articles表中有一个字段以m2m的关系连到Tags表中。已经把post, list等页面写完了,但是在写detail的时候,发现如果直接用article.tags引用,模板系统会报m2m的对象不能遍历的错,放狗找了一圈才知道需要使用article.tags.all作为for遍历的变量集,剩下的没啥说的了。

This entry was posted in 小企鹅Linux. Bookmark the permalink.

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>