HERE STACKOVER FLOW LINK OF QUESTIONS
:https://stackoverflow.com/questions/71232795/how-to-filter-by-month-from-template

---------------------------------------------------------------------------------------------------------------------------------------------

I'm attempting to channel a datetime field by month and year. Though no one 
can really say why while entering both month and year I get back a vacant 
set returned.

Model
class SpareParts(models.Model): vehicle = models.ForeignKey(Vehicle, 
on_delete=models.CASCADE) amount = models.IntegerField(blank=False, 
null=False) date = models.DateField(blank=False, null=False) 

And i want to filter on the basis of vehicle and month vise and here is 
mine view VIEWS.py
def view_spare(request): sparepart = SpareParts.objects.all() 
vehicle_filter = request.POST.get('vehicle') # get the value of the date 
field month_filter = request.POST.get('month') # get the value of the date 
field if vehicle_filter: if month_filter: sparepart = 
sparepart.filter(vehicle=vehicle_filter,date__month=month_filter).aggregate(Sum('amount'))
 
return 
render(request,'invoice/spare_parts_list.html',{'sparepart':sparepart}) 

and i want render the whole month sum of amount in template

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/746d4862-f349-4ccd-be54-5b894a115c02n%40googlegroups.com.

Reply via email to