1

我有以下模板

{% regroup product.hotel.facilities.all by facilitytype as facilities %}
{% for facility in facilities %}
       <h5>{{ facility.grouper }}</h5>

       <p class="tab-content-title bld">
          {% for i in facility.list %}
           <li>{{ i }}</li>
           {% endfor %}
          {% endfor %}

以及以下模型结构:

class Hotel(TranslatableModel):
    code = models.CharField(max_length=255)
    facilities = models.ManyToManyField('hotels.Facility',null=True)

class Facility(TranslatableModel):
    code = models.CharField(max_length=255, unique=True)
    facilitytype = models.ForeignKey(FacilityType, null=True, blank=True)

    translations = TranslatedFields(
        name=models.CharField(max_length=255, blank=True),
    )

但是当我运行页面时,我会看到下面。相反,我想查看按 facility_types 分组和区分的列表:有什么想法吗? 在此处输入图像描述

4

1 回答 1

3

您必须首先按 grouper 字段对数据进行排序。

于 2013-06-19T14:53:24.783 回答