Hi,
I am new user of Django.
I have a model.py.
class Clase(models.Model):
DAYS_OF_THE_WEEK={
"7": "MON",
"1": "TUE",
"2": "WED",
"3": "THU",
"4": "FRI",
"5": "SAT",
"6": "SUN",
}
name=models.CharField(max_length=30)
day=models.CharField(max_length = 20,choices = DAYS_OF_THE_WEEK,default = 'MON')
and a Class view to list the Class objects:
class list_clases(LoginRequiredMixin,ListView):
model=Clase
fields=['name','day']
template_name='website/listar_clases.html'
success_url=reverse_lazy('clase')
and the template:
<table class = "table table-bordered">
<thead>
<tr>
<th id="clase">CLASE</th>
<th id="clase">DIA DE CLASE</th>
<th id="opciones">Acciones</th>
</tr>
<tr>
{% for clase in object_list %}
<td> {{ clase.name }} </td>
<td> {{ clase.day}} </td>
<td> <a class="btn btn-primary" href="{% url 'reservar' clase.id %}">BOOK</a> </td>
</tr>
{% endfor %}
</thead
The problem is that I would like to show the weekday as ‘Monday’, ‘Tuesday’, etc… but the filter
|date:‘l’ for {{clase.day|date:‘l’ }} is not working. The Model, view and template work fine showing the weekday numbers if I remove the filter. I wonder if the problem could be that clase.day is considered as string, and tried the conversion to integer using {{clase.day|to_int}} but it gives an error (Invalid filter: ‘to_int’)
Any suggestion to show the weekdays in the template?
Thank you