Tuesday, April 30, 2019

Search and display results using calendar in Django

Hi Everybody,

I need help.

I want to perform search operation using calendars. I shall select two dates i.e. max_date which shall not be more than the current date but can be less and min_date, these two shall be the days range. The result fields are: in_count, out_count, and dwell_time. The output should sum up all the results of all the days which are between the max_date and min_date. How can I do that? Please help. Is there a need to define a model for this? I am completely clueless.  

Expected result is getting the output in the same form as in result_list.html with the result of all the fields of the days starting from min_date till max_date getting displayed and the min_date and max_date should also be shown in the template. Kindly help. 

My model :

  class Result(models.Model):        in_count   = models.PositiveIntegerField()      out_count  = models.PositiveIntegerField()      date_time  = models.DateTimeField()      time       = models.TimeField()        def __str__(self):
return "{},{},{},{}".format(self.in_count, self.out_count, self.date_time, self.time) 

My views.py

class ResultListView(ListView):        def get_queryset(self, *args, **kwargs):          qs = Result.objects.all()          print(self.request.GET)          query = self.request.GET.get("q", None)          if query is not None:              qs = qs.filter(                  Q(in_count__icontains=query) | Q(out_count__icontains=query) | Q(date_time__icontains=query) | Q(time__icontains=query))          return qs        def get_context_data(self, *args, **kwargs):          context = super(ResultListView, self).get_context_data(*args, **kwargs)            return context      class ResultDetailView(DetailView):      queryset = Result.objects.all()

My result_list.html
<div class="card-header">Result on {{ object.date_time}}</div>    <div class="card-body">      <h3 class="card-title"><a  href="{% url 'result:result' %}"style="color: white; ">Result of Model</a></h3>      <p class="card-text"> In Count {{ object.in_count }}</p>        <p class="card-text">Out Count {{ object.out_count}}</p>

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CALr9hQ2LV7WnQ3QT2jUy-O%3DO%3DNLtzeFfp7dk9RJXcx8dmxdVWw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment