Display logic should not be handled in the view but in your templates instead. Take a look at this documentation for further information:
https://docs.djangoproject.com/en/3.1/ref/templates/builtins/#if
Typically you would display data from your model through the use of Views and HTML templates. You would write a view function/class that gets called when a user goes to a particular URL. That view would use a queryset to pass the data from your model into the template. Going into that much detail here would be pretty wasteful as there is a TON of documentation available describing this process.
Basically you would need a view that looks kind of like this:
def your_view(request):
your_instances = YourModel.objects.all()
context = {
'your_instances': your_instances,
}
return render(request, 'your_html_template.html', context=context)
Then your template would look something like this:
<table>
{% for instance in your_instances %}
{% if instance.status == 'warning' %}
<tr style="background-color:#FF0000">
{% endif %}
{% if instance.status == 'ok' %}
<tr style="background-color:#000000">
{% endif %}
<td>{{ instance.field }}</td>
</tr>
{% endfor %}
</table>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…