File tree Expand file tree Collapse file tree 1 file changed +5
-4
lines changed Expand file tree Collapse file tree 1 file changed +5
-4
lines changed Original file line number Diff line number Diff line change 10
10
from django .db .models import Q
11
11
from DjangoEcommerce .settings import BASE_URL
12
12
from django .views .decorators .csrf import csrf_exempt
13
+ from .filters import ProductFilter
13
14
14
15
@login_required (login_url = "/admin/" )
15
16
def admin_home (request ):
@@ -264,10 +265,10 @@ class ProductListView(ListView):
264
265
paginate_by = 3
265
266
266
267
def get_queryset (self ):
267
- filter_val = self .request .GET . get ( "filter" , "" )
268
+ self . filterset = ProductFilter ( self .request .GET , queryset = super (). get_queryset () )
268
269
order_by = self .request .GET .get ("orderby" ,"id" )
269
- if filter_val != "" :
270
- products = Products . objects . filter ( Q ( product_name__contains = filter_val ) | Q ( product_description__contains = filter_val )) .order_by (order_by )
270
+ if self . request . GET . get ( "product_name" ) :
271
+ products = self . filterset . qs .order_by (order_by )
271
272
else :
272
273
products = Products .objects .all ().order_by (order_by )
273
274
@@ -283,9 +284,9 @@ def get_context_data(self,**kwargs):
283
284
context ["filter" ]= self .request .GET .get ("filter" ,"" )
284
285
context ["orderby" ]= self .request .GET .get ("orderby" ,"id" )
285
286
context ["all_table_fields" ]= Products ._meta .get_fields ()
287
+ context ["all_products" ]= Products .objects .all ()
286
288
return context
287
289
288
-
289
290
class ProductEdit (View ):
290
291
291
292
def get (self ,request ,* args ,** kwargs ):
You can’t perform that action at this time.
0 commit comments