view: add product_list.
This commit is contained in:
parent
9409eeb94a
commit
c6ca0feb11
@ -0,0 +1,13 @@
|
||||
<form action="" method="get">
|
||||
<label>Filtro por nombre:</label>
|
||||
<input type="text" name="name" value="{{ request.GET.name }}">
|
||||
<button type="submit">Filtrar</button>
|
||||
</form>
|
||||
{% block content %}
|
||||
<h1>Lista de productos</h1>
|
||||
<ul>
|
||||
{% for obj in object_list %}
|
||||
<li>{{ obj.name }} ({{ obj.id }})</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endblock %}
|
@ -8,6 +8,7 @@ urlpatterns = [
|
||||
path("comprar", views.buy, name="buy"),
|
||||
path("compras", views.purchases, name="purchases"),
|
||||
path("productos", views.products, name="products"),
|
||||
path("lista_productos", views.ProductListView.as_view(), name='product_list'),
|
||||
path("importar_productos", views.import_products, name="import_products"),
|
||||
path("cuadrar_tarro", views.reconciliate_jar, name="reconciliate_jar"),
|
||||
path("cuadres", views.reconciliate_jar, name="reconciliations"),
|
||||
|
@ -2,6 +2,7 @@ from django.shortcuts import render
|
||||
from django.http import HttpResponse, HttpResponseRedirect, JsonResponse
|
||||
from django.template import loader
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.views.generic import ListView
|
||||
|
||||
from .models import Sale, Product, ProductCategory, Payment
|
||||
from .forms import ImportProductsForm, PurchaseForm, LineaFormSet, ReconciliationJarForm
|
||||
@ -124,3 +125,14 @@ def handle_import_products_file(csv_file):
|
||||
product.categories.clear()
|
||||
for category in categories:
|
||||
product.categories.add(category)
|
||||
|
||||
|
||||
class ProductListView(ListView):
|
||||
model = Product
|
||||
template_model = 'don_confiao/product_list.html'
|
||||
|
||||
def get_queryset(self):
|
||||
name = self.request.GET.get('name')
|
||||
if name:
|
||||
return Product.objects.filter(name__icontains=name)
|
||||
return Product.objects.all()
|
||||
|
Loading…
Reference in New Issue
Block a user