hi Everyone , I have created a application in which I want to filter table between dates (from and to)dates But not getting a desired output .
This is my models.py class data(models.Model): machinename = models.CharField(max_length=100) activity = models.CharField(max_length=255) description = models.CharField(max_length=500) datetime = models.DateField() This is my html page <form method="POST"> {% csrf_token %} <center> <input type="text" id="search_all" placeholder="Search Machine.." style="width:250px; height:30px"> <hr/> >From :<input type="date" name="fromdate"/> To :<input type="date" name="todate"/> <input type="submit" value="Search" /> <hr/> <br> <div style="width:550px; height:350px; overflow:auto; "> <table border="4" bgcolor="grey"> <thead> <tr style="text-align:center; color:black; border:1px solid black; background-color: #f1f1f1;"> <th>Datetime</th> <th>Machine Name</th> <th>Activity</th> <th>Description</th> </tr> </thead> <tbody> {% for results in formdata %} <tr style="text-align:center; color:black; border:1px solid black"> <td>{{results.datetime}}</td> <td>{{results.machinename}}</td> <td>{{results.activity}}</td> <td>{{results.description}}</td> {% endfor %} </tr> </tbody> </table> </center> </form> This is my views.py def showresults(request): if request.method == "POST": fd = request.POST.get['fromdate'] td = request.POST.get['todate'] search = data.objects.filter(Q(datetime__gte=fd) & Q(datetime__lte=td)) d = {'search': search, 'fd': fd, 'td': td} return render(request, 'dashboard.html', d) else: result = data.objects.all() return render(request, 'dashboard.html', {'formdata': result}) Please help me.. Thank You !! -- 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/f2e82200-697e-4deb-b6f5-68e48e1c4a81n%40googlegroups.com.