When I select a date range, I want it to show the number of hard drives saved in the database and the total size of these hard drives in the selected date range.
would be glad if you help.
FILTERS.PY
class MateryalFiltrele(django_filters.FilterSet):
baslangicTarihi = DateFilter(field_name="eklenmeTarihi", lookup_expr="gte", label='')
bitisTarihi = DateFilter(field_name="eklenmeTarihi", lookup_expr="lte", label='')
class Meta:
model = MateryalEkle
fields = ('cinsi','materyalBoyut')
MODELS.PY
class MateryalEkle(models.Model):
MATERYALCINSI = [
('USB', 'USB'),
('HDD', 'HDD'),
]
cinsi = models.CharField(max_length=50, choices=MATERYALCINSI)
materyalBoyut = models.IntegerField(max_length=5)
eklenmeTarihi = DateField(auto_now_add=True)
def __str__(self):
return self.cinsi
VIEWS.PY
def istatistik(request):
topla = MateryalEkle.objects.filter(cinsi='HDD').aggregate(tumhddtopla=Sum('materyalBoyut'))
toplafiltre = MateryalFiltrele(request.GET, queryset=topla)
return render(request, 'delil/istatistikler.html', {'toplafiltre':toplafiltre})
HTML
<div>
{{ toplafiltre.form.baslangicTarihi | as_crispy_field }}
{{ toplafiltre.form.bitisTarihi | as_crispy_field }}
<button type="submit" ></button>
</div>
<table class="table mt-5">
<thead>
<tr>
{% for tekil in hddToplaFiltre.qs %}
<th class="ubold text-info ufo60" scope="col">{{tekil.tumhddtopla}}</th>
{% endfor %}
</tr>
</thead>
</table>