i'm new on Django, and I would like to know how can I create a kind of filter so that only an object appears if it meets a condition in one of its attributes. I tried to do it with tags in the template but it did not work and I don't know if it is the most efficient way. The case is for example that I would like to see in my table the objects that in their attribute "asignar" have a specific value for example the text "Pedro". I'm open to suggestions that do not necessarily apply with labels.
Models.py:
class reporte_fallo(models.Model):
num_inventario = models.CharField(max_length=25)
serie = models.CharField(max_length=25)
falla = models.TextField()
descripcion = models.TextField()
LOAN_STATUS = (
('m', 'Maintenance'),
('o', 'On loan'),
('a', 'Available'),
('r', 'Reserved'),
)
area = models.CharField(max_length=1,choices=LOAN_STATUS,blank=True)
fecha = models.DateField(auto_now=False, auto_now_add=True)
asignar = models.CharField(max_length=20, default=True)
fecha_comp = models.DateField(default=timezone.now)
View.py:
class reportelist(ListView):
model = reporte_fallo
template_name = 'formulario/reporte_list_jefe.html'
Template.html (This is my template that did not work using tags in this case the part "and report.assign == "Pedro" on the if, it just send the message "The list is empty")
<tbody>
{% if object_list and reporte.asignar == "Pedro" %}
{% for reporte in object_list %}
<tr>
<td>{{reporte.id}}</td>
<td></td>
<td>{{reporte.falla}}</td>
<td>{{reporte.fecha}}</td>
<td>{{reporte.area}}</td>
<td>{{reporte.asignar}}</td>
<td>{{reporte.fecha_comp}}</td>
<td></td>
<td>
<a href="{% url 'formulario:reporte_editar' reporte.id %}">Asignar</a>
<a href="{% url 'formulario:reporte_eliminar' reporte.id %}">Eliminar</a>
</td>
</tr>
{% endfor %}
{% else %}
<h1>The list is empty</h1>
{% endif%}
</tbody>
I hope your answer thnks a lot!