【发布时间】:2012-11-04 20:07:31
【问题描述】:
我的数据库中保存了多个对象,但我只想在我的查询集中显示唯一的项目,并且如果它们实际上保存了一个项目。
models.py
class Everything(models.Model):
profile = models.ForeignKey(User)
playlist = models.CharField('Playlist', max_length = 2000, null=True, blank=True)
platform = models.CharField('Platform', max_length = 2000, null=True, blank=True)
video = models.CharField('VideoID', max_length = 2000, null=True, blank=True)
def __unicode__(self):
return u'%s %s %s %s' % (self.profile, self.playlist, self.platform, self.video)
views.py
playlist2 = Everything.objects.filter(profile=request.user)
模板
<select name ="playlist2">
{% for item in playlist2 %}
<option value="{{item.playlist}}">{{item.playlist}}</option>
{% endfor %}
</select>
不必有播放列表,因为 null=True 和 blank=True。播放列表中的某些项目也可能重复。如何仅显示其中包含值的不同项目?
【问题讨论】:
标签: python django templates view model