Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 聚合解决方案Django_Python_Django_Aggregation - Fatal编程技术网

Python 聚合解决方案Django

Python 聚合解决方案Django,python,django,aggregation,Python,Django,Aggregation,我正在尝试获取已售出产品的总数,代码如下: 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)

我正在尝试获取已售出产品的总数,代码如下:

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))

我无法使用此视图。

ventas=ventas.objects.aggregate(total\u payment=Sum('totalventa')) 我认为,如果你在各自的数据库中有数据,它应该工作得很好。 此操作的输出将是一个字典。 例如{'total_payment':十进制('xx.xx')}格式

def ventas_anio(请求):


我懂西班牙语,但我想如果你能用英语发布代码,人们会喜欢的。谢谢,下次我会采纳你的建议;)代码是英文的,只是变量不是。这应该不是什么大问题。@gersande我同意你的看法……你知道如何计算销售产品的总额吗?@gersande:)好的,祝你学习python好运这是一种很棒的编程语言你好,谢谢……但我有一个错误“'int'对象不可编辑”:(请您跳过错误跟踪,以便我可以帮助您进一步挖掘根本原因。
ventas = Ventas.objects.all().aggregate(total_payment=Sum('totalventa'))
sum_ventas = ventas['total_payment']
return render_to_response('ventasanual.html',{'datos':sum_ventas}, context_instance=RequestContext(request))