I have the following ListView which I want to use also for filtering the results
class Membresias(ListView):
model = Cliente
template_name = 'main/membresias.html'
def get_queryset(self):
nombre = self.request.GET.get('nombre')
if nombre is None:
return Cliente.objects.all()
else:
return Cliente.objects.filter(nombre = nombre).values()
when the 'nombre' variable is not None it show the results, PROBLEM: but when I leave it blank or is None, it does not show any records at all and according to the validation the queryset should retrieve all the records.
Here is part of the html for the table
<div class = "container">
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Nombre</th>
<th scope="col">Email</th>
<th scope="col">Teléfono</th>
<th scope="col">Activo</th>
</tr>
</thead>
<tbody>
{% for cliente in object_list %}
<tr>
<th scope="row"><a href="{{ cliente.get_absolute_url }}">{{cliente.id}}</a></th>
<td>{{cliente.nombre}}</td>
<td>{{cliente.email}}</td>
<td>{{cliente.telefono}}</td>
{% if cliente.activo == False %}
<td><input type="checkbox" readonly class="form-check-input mt-1" id="Estatus" disabled value={{cliente.activo}}></td>
{% else %}
<td><input type="checkbox" readonly class="form-check-input mt-1" checked id="staticEmail" disabled value={{cliente.activo}}></td>
{% endif %}
</tr>
{% endfor %}
</tbody>
</table>
</div>