I am new to python and it has been difficult for me to formulate a logic for this problem, it is necessary to subtract the amount entered from an article minus the stock that is already in the article table. here the classes:
class Pedido(models.Model):
especialidad = models.ForeignKey('Especialidad')
fecha_entrega = models.DateTimeField(auto_now_add=False)
fecha_pedido = models.DateTimeField(auto_now_add=True,null=True, blank=True)
articulo = models.ForeignKey('Articulo')
cantidad = models.CharField(max_length=999, blank=True)
pendiente = models.CharField(max_length=999, null=True, blank=True)
def __str__(self):
return '{}'.format(self.articulo, self.cantidad)
class Articulo(models.Model):
cod_experto = models.CharField(max_length=999, primary_key=True, blank=True)
nombre = models.CharField(max_length=999, blank=True)
descripcion = models.CharField(max_length=999, blank=True, null=True)
info_bodega = models.ForeignKey(Bodega, null=True, blank=True, on_delete=models.CASCADE)
stock = models.CharField(max_length=999, blank=True)
extmin = models.CharField(max_length=999, blank=True, null=True)
extmax = models.CharField(max_length=999, blank=True, null=True)
def __str__(self):
return '{}'.format(self.nombre)
I would greatly appreciate the solution. Success! here the view (modified) at the tip of query set:
def succes(self):
articulo = Pedido.objects.filter(cod_experto=self.object.pk)
for x in articulo:
cant_articulo = Articulo.objects.filter(id=x.articulo_id)
for z in cant_articulo:
total = x.cantidad - z.stock
update = Articulo.objects.values('cantidad').filter(id=x.articulo_id).update(stock=total)
return redirect(reverse('usuario:index.html', kwargs={'pk': self.object.pk}))
return render(request, 'usuario:index.html' ,{'pk':pk})
I can not get an error to work:
Reverse for 'succes' with arguments '('',)' and keyword arguments '{}' not found. 1 pattern(s) tried: ['Solicitudes/confirmar/(?P<articulo>\d+)/$']
url app: url(r'^confirmar/(? P<articulo>\d+)/$',login_required(Pedidoapp.views.succes), name='succes'),
url global: url(r'^Solicitudes/', include(Pedidoapp.urls, namespace="usuario")),
mark this as an error in the index.html:
Approve