我有一个像这样的课程
class udl(models.Model):
uid = models.IntegerField()
url = models.CharField(max_length=1000,default='')
假设我有这样的表
10|data1
10|data2
11|data3
12|data4
如果id为10,我如何在data1和data2等模板中显示数据列表。
{%for d in dislike%}
<ul>
<div class="row">
<div class="col-md-6 col-sm-6 col-lg-6">
<div class="box box-danger box-solid collapsed-box">
<div class="box-header with-border">
<h3 class="box-title" style="word-wrap:break-word;width:560px;" data-widget="collapse">{{d.title}}</h3>
<div class="box-tools pull-right">
<i class="fa fa-thumbs-o-down"></i><span data-original-title="Number of People Hate it" data-toggle="tooltip" title="" class="badge bg-red">{{d.count}}</span>
<button class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-plus"></i></button>
</div><!-- /.box-tools -->
</div><!-- /.box-header -->
<div style="display: none;" class="box-body">
{%for u in udlist%}
<ul class="nav nav-stacked">
<li>
<a href="{{u.url}}" target="_blank">{{u.url}}***#Here how can i show list of url data for the individual id.***
</a>
</li>
</ul>
{%endfor%}
</div><!-- /.box-body -->
</div>
</div>
</ul>
{%endfor%}
答案 0 :(得分:2)
这应该有效:
udl.objects.filter(uid=10) # Where udl is your model class
应返回uid=10