简体   繁体   中英

why filter doesn't change value in iteration in django template

I have custome filter in to_and.py file for getting verbose name

from django import template

register = template.Library()

@register.filter
def verbose_name(objects):
    return objects._meta.verbose_name

but when I get the value in view it only give me the first model name in iteration my code queryset has two indivial model

 {% load to_and %}
                 {{links}}
              {% for link in links %}
                     {% if link|verbose_name == "Unit" %}
                            {{link|verbose_name}}
                            {{link.id}}
                     {% endif %}
              {% endfor %}       

see the out put of this code在此处输入图片说明

in models I forget to change the verbose name of SubUnits

just Change the verbose_name in models
class Meta:
        """Meta definition for Unit."""

        verbose_name = 'SubUnit'
        verbose_name_plural = 'SubUnits'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM