Question about <li> from integer models

31 views
Skip to first unread message

Hansel Johansyah

unread,
May 30, 2022, 6:06:07 AM5/30/22
to Django users
Hi Everyone

I wanna question about the integer would input by models, with some class ClassName
numb = models.IntegerField()
and the views is :
number = ClassName.objects.values_list('numb', flat=True).distinct()
then the templates is :
<ul class="a big">
<li class="a">1</li> 
<li class="a">2</li> 
<li class="a">3</li>
<li class="a">4</li>
<li class="a">5</li>
<li class="extra"></li>
</ul>
so i call the number from django admin with
{% for i in numb %}
 <li class="a">{{i}}</li>
 <li class="a">{{i}}</li>
 <li class="a">{{i}}</li>
 <li class="a">{{i}}</li>
 <li class="a">{{i}}</li>
 <li class="extra">{{i}}</li>
{% endfor %}
I expect the html will showing :
123456 the number split by the li class
but the current problem is, the number showing all in every <li>, be like
123456 123456 123456 123456 123456 123456

I hope somebody will help me, Thank you

Regards

Chiranjeevi Kodati

unread,
May 30, 2022, 9:08:02 AM5/30/22
to Django users
Hi, 

As per my understanding, the thing you want to achieve can be done using the below code.

<ul class="a big">
    {% for i in number %}
       <li class="a">{{i}}</li>
    {% endfor %}
     <li class="extra"></li>
</ul>

In that way, if the queryset contains 1 to 6 integers, you will loop over them and create 6 li items and place it inside ul tag element.

Regards
Chiranjeevi

Hansel Johansyah

unread,
May 30, 2022, 9:12:51 AM5/30/22
to Django users
Hi
Thank you for response
anyway I have trying your tips, but It not works

Reply all
Reply to author
Forward
0 new messages