Wednesday, May 1, 2019

Re: Search and display results using calendar in Django

My Calendar.html:

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"> <!-- Optional theme --> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/css/bootstrap-datetimepicker.min.css" /> <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.6/moment.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/js/bootstrap-datetimepicker.min.js"></script> <div class="container"> <div class='col-md-5'> <div class="form-group"> <div class='input-group date' id='datetimepicker6'> <input type='text' class="form-control" /> <span class="input-group-addon"> <span class="glyphicon glyphicon-calendar"></span> </span> </div> </div> </div> <div class='col-md-5'> <div class="form-group"> <div class='input-group date' id='datetimepicker7'> <input type='text' class="form-control" /> <span class="input-group-addon"> <span class="glyphicon glyphicon-calendar"></span> </span> </div> </div> </div> </div> <script type="text/javascript"> jQuery(function () { jQuery('#datetimepicker6').datetimepicker(); jQuery('#datetimepicker7').datetimepicker({ useCurrent: false //Important! See issue #1075 }); jQuery("#datetimepicker6").on("dp.change", function (e) { jQuery('#datetimepicker7').data("DateTimePicker").minDate(e.date); }); jQuery("#datetimepicker7").on("dp.change", function (e) { jQuery('#datetimepicker6').data("DateTimePicker").maxDate(e.date); }); }); </script>

Now, I want to select multiple dates using this, say start_date and end_date which will filter the dates between that range and then sum the value of in_count and out_count and display it to the user.

So, far what I think I should use is, but I am not sure how to do it and display the result to the user. Someone please help me here.

Result.objects.filter(
    date_time__range=[start_date, end_date]  ).aggregate(Sum('in_count'), Sum('out_count'))

--
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/CALr9hQ1VZHYd%2BNSbU_WZXy4mbW0wHabaVvkz6LTyt0%3DpheyPew%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment