view: add product_list.
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user