Reputation: 3368
models.py
class ReportType(models.Model):
report = models.ForeignKey(Report)
title = models.CharField('Incident Type', max_length=200)
type = models.ForeignKey(Types, null=False, default=False)
class Types(models.Model):
user = models.ForeignKey(User, null=True)
title = models.CharField('Incident Type', max_length=200)
parent_type_id = models.CharField('Parent Type', max_length=100, null=True, blank=True)
is_active = models.BooleanField('Is Active', default=True)
views.py
def method(request):
report_types = ReportType.objects.filter(report=int(report_id)).select_related("type")[:3]
return{'what_tab': report_types,}
template.html
{% if leftbar.what_tab.0.type.title%}{{ leftbar.what_tab.0.type.title}}{%endif%}
I am storing the integer value in type column in ReportType model.
I am able to display the 1st item alone into template.I don't know how to display all the saved item into template.
Need help.
Thanks
Upvotes: 0
Views: 46
Reputation: 99670
I dont know what leftbar
is, but assuming you got all the other stuff right,
{% for tab in leftbar.what_tab %}
{% if tab.type.title %}
{{ tab.type.title}}
{% endif %}
{% ifnotequal forloop.counter leftbar.what_tab %},{% endnotifequal %}
{% endfor %}
Since title
is not nullable, {% if tab.type.title %}
should never be the case.
Upvotes: 1