When I enter my user profile page, I want it to see the total number of orders until today. i tried aggregate and annonate but it's not work. I hope so i use filter method but i don't know how to do it.
Orders count = adet in model
I added ""if siparis.bayi_id == user.id"" so that the user entering can take action on his orders.
Temp Html
{% for siparis in siparis %}
{% if siparis.bayi_id == user.id %}
<strong>{{ a }}</strong><br><small>Sipari?ler Toplam?</small>
{% endif %}
{% endfor %}
Model Siparis means order
class Siparis(models.Model):
bayi = models.ForeignKey('auth.User', verbose_name='bayi', on_delete=models.CASCADE, related_name='bayi',limit_choices_to={'groups__name': "BayiGrubu"})
urun = models.ForeignKey(Urun, on_delete=models.CASCADE)
adet = models.IntegerField()
tarih = models.DateTimeField()
status = models.BooleanField()
@property
def miktar(self):
return (self.adet * self.urun.fiyat)
@property
def fiyat(self):
return self.urun.fiyat
class Meta:
verbose_name = 'Bayi Sipari?'
verbose_name_plural = 'Bayi Sipari?leri'
views
def bayi_bayidetay(request):
siparis = Siparis.objects.all()
urunler = Urun.objects.all()
bayiler = bayi_bilgi.objects.all()
a = Siparis.objects.aggregate(Sum("adet"))
return render(request,'bayi/bayi_detay.html',{'bayiler':bayiler,'siparis':siparis,'urunler':urunler, 'a': a})
Thank you
question from:
https://stackoverflow.com/questions/65645501/see-how-many-orders-he-has-on-his-profile-page-django 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…