4LuckyMove / managing-tasks

Develop a simple web application for managing tasks.
0 stars 0 forks source link

filtering #3

Open DenisIschenko opened 2 years ago

DenisIschenko commented 2 years ago

q = self.request.GET.get('q') if self.request.GET.get('q') else None may be replaced by q = self.request.GET.get('q', None)

Also i do not understand logic start_date = datetime.strptime(self.request.GET.get('startDate'), '%d.%m.%Y').date() \ if self.request.GET.get('startDate') else self.request.POST.get('startDate') basically if in get do not present date you get it from post, but do not convert to date

also logic if q != None and start_date == None and end_date == None: task_filter = Task.objects.filter(status__exact=q) elif q == None and start_date != None and end_date != None: task_filter = Task.objects.filter( Q(creation_date__date__range=[start_date, end_date]) | Q(creation_date__date__range=[end_date, start_date]) ) elif q != None and start_date != None and end_date != None: task_filter = Task.objects.filter( Q(status__exact=q, creation_date__date__range=[start_date, end_date]) | Q(status__exact=q, creation_date__date__range=[end_date, start_date]) ) else: task_filter = Task.objects.all()

can be simplified if you will collect dates and status in array and after that send to filter

4LuckyMove commented 2 years ago

q = self.request.GET.get('q') if self.request.GET.get('q') else None may be replaced by q = self.request.GET.get('q', None)

At the moment I had a gap in knowledge at this point. I figured out how queryset works in django. At the moment, I understand that I can simplify and do even better, as an option, use the django-filter library, create a separate filter.py file and write classes for filtering there.

"Also i do not understand logic start_date = datetime.strptime(self.request.GET.get('startDate'), '%d.%m.%Y').date() \ if self.request.GET.get('startDate') else self.request.POST.get('startDate') basically if in get do not present date you get it from post, but do not convert to date"

I used the conversion, since the input that returns the date to me has the value "DD.MM.YYYY", django uses the date "YYYY-MM-DD" - and I got an error that the date format was not suitable and this method was found for Google solution on stackoverflow.

can be simplified if you will collect dates and status in array and after that send to filter

So I will go deeper into this issue.