'dict' object has no attribute 'model' Issue

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>

image

When asking for help with an error message, it’s helpful if you post the complete traceback message and not just the summary line. (You should also enclose it between the lines of three backticks as well, just like you do with code.)

I am sorry fır this. I got it. Will you answer my question?

That’s not the traceback.

We’re looking for the information that would be presented in your console where you’re running runserver.

1 Like

Thank you for your interest. I solved the problem.