【发布时间】:2013-05-27 22:55:18
【问题描述】:
我正在尝试获取已售产品的总数,代码如下:
models.py
class Ventas(models.Model):
codigoventa = models.CharField(max_length=7, unique=True)
codigocliente = models.ForeignKey('Clientes')
Fecha_registro = models.DateTimeField("Fecha de edicion", auto_now_add=True)
totalventa = models.DecimalField(max_digits=10, decimal_places = 2)
codigosucursal = models.ForeignKey('Sucursales')
totalventa = models.IntegerField()
def __unicode__(self):
return self.codigoventa
Views.py
def ventas_anio(request):
ventas = Ventas.objects.all().aggregate(total_payment=Sum('totalventa'))
return render_to_response('ventasanual.html',{'datos':ventas}, context_instance=RequestContext(request))
我无法使用此视图。
【问题讨论】:
-
我懂西班牙语,但我想如果你能用英语发布代码,人们会喜欢它。
-
谢谢,下次采纳你的建议;)
-
代码是英文的,只是变量不是。这应该不是什么大问题。
-
@gersande 我同意你的看法...你知道如何获得已售产品的总数吗?
-
@gersande :) ok 祝你学习 Python 好运,它是一门很棒的编程语言
标签: python django aggregation