尝试将查询集的某些字段输出到屏幕时,它们是唯一的。
基于类的视图:
class PostListView(ListView):
queryset = Post.objects.distinct()
template_name = 'list/list.html'
context_object_name = 'posts'
ordering = ['-date_posted']
HTML:
{%for post in posts%}
<option value="{{post.vehicle_type}}" >{{post.vehicle_type}}</option>
{%endfor%}
如何使此特定循环唯一,同时又可以在同一页面上的另一个循环中使用所有对象