Use get_FOO_display for choices fields in templates

This commit is contained in:
Christopher C. Wells 2019-11-09 14:05:55 -08:00 committed by Christopher Charbonneau Wells
parent cce4855b52
commit b6733650dc
5 changed files with 8 additions and 8 deletions

View File

@ -154,11 +154,11 @@ class DiaperChange(models.Model):
def attributes(self):
attributes = []
if self.wet:
attributes.append(DiaperChange._meta.get_field('wet').name)
attributes.append(self._meta.get_field('wet').verbose_name)
if self.solid:
attributes.append(DiaperChange._meta.get_field('solid').name)
attributes.append(self._meta.get_field('solid').verbose_name)
if self.color:
attributes.append(self.color)
attributes.append(self.get_color_display())
return attributes
def clean(self):

View File

@ -28,7 +28,7 @@
<th scope="row"><a href="{% url 'core:child' change.child.slug %}">{{ change.child }}</a></th>
<td class="text-center">{{ change.wet|bool_icon }}</td>
<td class="text-center">{{ change.solid|bool_icon }}</td>
<td>{{ change.color }}</td>
<td>{{ change.get_color_display }}</td>
<td>{{ change.time|date:'n/j/y G:i' }}</td>
<td class="text-center">
<div class="btn-group btn-group-sm" role="group" aria-label="{% trans "Actions" %}">

View File

@ -28,8 +28,8 @@
{% for feeding in object_list %}
<tr>
<th scope="row"><a href="{% url 'core:child' feeding.child.slug %}">{{ feeding.child }}</a></th>
<td>{{ feeding.method }}</td>
<td>{{ feeding.type }}</td>
<td>{{ feeding.get_method_display }}</td>
<td>{{ feeding.get_type_display }}</td>
<td>
{% if feeding.amount %}
{{ feeding.amount }}

View File

@ -13,7 +13,7 @@
{% block content %}
{% if feeding %}
{{ feeding.type }}, {{ feeding.method }}
{{ feeding.get_type_display }}, {{ feeding.get_method_display }}
{% if feeding.amount %}
({{ feeding.amount }})
{% endif %}

View File

@ -5,7 +5,7 @@
{% block title %}
{% if feeding %}
<div class="display-4 text-center">{{ feeding.method }}</div>
<div class="display-4 text-center">{{ feeding.get_method_display }}</div>
{% else %}
{% trans "None" %}
{% endif %}