1

模型.py

class ReportType(models.Model):
    report = models.ForeignKey(Report)
    title = models.CharField('Incident Type', max_length=200)

    def __unicode__(self):
        return self.title

视图.py

def where(request):
    user=request.user
    try:
        report = Report.objects.get(user=user.id)
    except:
        report = None
    reporttype = ReportType.objects.all()
        .          .        .
        .          .        .
    return render(request, 'incident/where.html',
        {
            'newreport_menu': True,
            'reporttype':reporttype
    })

它以这种形式给我输出。[<ReportType: Bike parking>, <ReportType: car parking>]如何显示像这样的值“自行车停车场,停车场”。

4

1 回答 1

2

使用for模板标签

{% for rt in reporttype %}
    {{ rt.title }}
{% endfor %}
于 2013-05-31T13:48:49.787 回答