【问题标题】:Django manytomany in template format模板格式的 Django manytomany
【发布时间】:2011-06-22 13:42:05
【问题描述】:

在我的一个模型中,我有一个类别字段,它是多对多配置。

我想知道如何在模板中获得以下输出。

第 1 类、第 2 类、第 3 类和第 4 类

所以基本上用逗号分隔每个类别,除了最后一个用“and”替换

【问题讨论】:

    标签: django django-templates django-template-filters


    【解决方案1】:
    {% for category in myob.categories.all %}
      {{ category }}
      {% if not forloop.last %},{% else %} and {% endif %}
    {% endfor %}
    

    【讨论】:

      猜你喜欢
      • 2018-04-05
      • 1970-01-01
      • 2018-05-05
      • 1970-01-01
      • 2014-10-11
      • 1970-01-01
      • 1970-01-01
      • 2012-01-16
      • 1970-01-01
      相关资源
      最近更新 更多