I have my function buscar
, but I get this error:
Here is the code:
view.py
class ListarTipoAlmacen(ListView):
model = Tipo_almacen
template_name = 'tipo_almacen/lista_tipo_almacen.html'
paginate_by = 10
def get(self, request, *args, **kwargs):
buscar_descripcion = request.GET.get('buscar_descripcion', '')
lista_tipo_almacen = Tipo_almacen.objects.filter(descripcion__contains=buscar_descripcion)
if buscar_descripcion == '':
context['error'] = 'ingrese dato por favor'
else:
if not buscar_descripcion:
context['error'] = 'el dato ingreso no existe'
return render_to_response('tipo_almacen/lista_tipo_almacen.html', {'lista_tipo_almacen': lista_tipo_almacen}, context['error'])
def get_context_data(self, **kwargs):
context = super(ListarTipoAlmacen, self).get_context_data(**kwargs)
lista_tipo_almacen = Tipo_almacen.objects.all().order_by('descripcion')
paginator = Paginator(lista_tipo_almacen, self.paginate_by)
page = self.request.GET.get('page')
try:
pagina = paginator.page(page)
except PageNotAnInteger:
pagina = paginator.page(1)
except EmptyPage:
pagina = paginator.page(paginator.num_pages)
context['lista_tipo_almacen'] = pagina
return context
HTML
<div class="row">
<div class="col-lg-12">
<div class="form-group">
<div class="col-md-4">
<input id="textinput" name="textinput" placeholder="ingrese nombre" class="form-control input-md" type="text">
</div>
</div>
<div class="form-group">
<div class="col-md-2">
<button id="singlebutton" name="singlebutton" class="btn btn-primary">Buscar</button>
</div>
</div>
</div>
</div>
<br><br>
<div class="panel panel-primary">
<div class="panel-heading">
<h4>Lista de Tipo de almacen</h4>
</div>
<table class="table">
<th>Nombres</th>
<th>Acciones</th>
<tbody>
{% for data in lista_tipo_almacen %}
<tr>
<td>
{{data.descripcion}}
<td>
<a href="{% url 'editar_tipo_almacen' data.pk %}">Editar <span class="glyphicon glyphicon-edit"></span></a>
<a href="{% url 'eliminar-tipo-almacen' data.pk %}" data-toggle="modal_almacen" data-target="#modal_almacen" data-id="{{ data.descripcion }}">Eliminar <span class="glyphicon glyphicon-trash"></span></a>
</tr>
{% endfor %}
</tbody>
</table>
</div>