Wednesday, March 11, 2015

soy nuevo en django, y estoy haciendo un proyecto les agradezco su ayuda.

estoy resien empezando a programar en django, y tengo el siguiente problema, les agradecería mucho su ayuda.


class Producto(models.Model):
codigo = models.CharField(max_length=10, unique=True) nombre = models.CharField(max_length=200, unique=True)
descripcion = models.TextField(max_length=400) categoria = models.ForeignKey(Categoria) precio_compra = models.DecimalField(max_digits=5, decimal_places=2, default=0.00) stock = models.IntegerField()
def __unicode__(self): return self.nombre def preeciototal(self): precio_total=self.precio_compra*self.stock return precio_total Y la siguiente Vista
class MainPanelView(TemplateView): template_name = 'farmacia/panel.html' mode = Producto def get_context_data(self, **kwargs): context['cantidad'] = context['producto'].count() context['total'] = Producto.objects.aggregate(Sum('precio_compra'))['precio_compra__sum'] context['total_productos'] = Producto.objects.aggregate(Sum('stock'))['stock__sum'] #obtengo la variable stock context['stock'] = Producto.objects.values('stock') #obtengo la variable precio_compra context['precio_compra'] = Producto.objects.values('precio_compra') #context['total'] = context['stock']*context['precio_compra'] product=Producto #total = Producto.preeciototal() return context



el precio lo saco en el models.
def preeciototal(self): precio_total=self.precio_compra*self.stock return precio_total

como lo aria en las vistas y no en el models.

mi problema es.
como saco el precio total que la lógica seria.
400*520=208000
500*1150=1650
600*1440=864000

208000+1650+864000=Precio total..

no se como hacerlo en las vistas..


Gracias..

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/97f5ff23-bc8f-4146-a74f-085493f92f65%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment