Advertisement
greathector7

listwiev no filtra

Apr 13th, 2019
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.43 KB | None | 0 0
  1. class ExpedienteList(ListView):
  2.     model = expediente
  3.     template_name = 'expediente/expedienteList.html'
  4.     ordering = '-fecha'
  5.  
  6.     def get_queryset(self):
  7.         # por defecto solo trae los expedientes del dia
  8.         hoy = date.today()
  9.         qs = super().get_queryset()
  10.         filtros2 = {}
  11.  
  12.         # verificamos que vengan por peticion para entrar en el ciclo
  13.         if self.request.method == 'GET':
  14.             # declaramos la variables que vienen del formulario
  15.             fecha1 = self.request.GET.get('fechad')
  16.             fecha2 = self.request.GET.get('fechah')
  17.             dato = self.request.GET.get('dato')
  18.             print(dato)
  19.             # declaro mi diccionario para el filtro
  20.             filtros2 = {}
  21.            
  22.             if fecha1 or fecha2 or dato:
  23.                 if fecha1:
  24.                     if fecha2:
  25.                         filtros2.update({"fecha__range": (fecha1, fecha2)})
  26.                     else:
  27.                         filtros2.update({"fecha__date": (fecha1)})
  28.                 elif fecha2:
  29.                     filtros2.update({"fecha__date": (fecha2)})
  30.                 if dato:
  31.                     filtros2.update({"cuenta__icontains": (dato)})
  32.             else:
  33.                 return qs.filter(fecha__date=date.today())
  34.  
  35.             logging.info('filtro final a aplicar:')
  36.             logging.debug(filtros2)
  37.             return qs.filter(**filtros2).order_by('-fecha')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement