Ich habe diesen Fehler, können Sie mir helfen? Sie müssen den "Quantity" -Wert vom "Pedido" - "Stock" -Modell des "Articulo" -Modells subtrahieren und dann das Bestandsergebnis speichern.nicht unterstützte Operandentyp (en) für - =: 'str' und 'int'
in line: articulo.stock - = pedido.cantidad
def Update_stock(request, id_pedido, cod_experto):
if request.method == 'GET':
pedido = Pedido.objects.get(id=id_pedido)
articulo = Articulo.objects.get(pk=cod_experto)
articulo.stock -= pedido.cantidad
articulo.save()
return render(request, 'admindata.html', {'pedido':pedido, 'articulo':articulo})
models.py:
class Pedido(models.Model):
articulo = models.ForeignKey('Articulo')
fecha_pedido = models.DateTimeField(auto_now_add=True,null=True, blank=True)
cantidad = models.IntegerField(blank=True)
def __str__(self):
return '{}'.format(self.especialidad, self.articulo, self.cantidad, self.estado)
class Articulo(models.Model):
cod_experto = models.CharField(max_length=999, primary_key=True, blank=True)
nombre = models.CharField(max_length=999, blank=True)
on_delete=models.CASCADE)
stock = models.CharField(max_length=999, blank=True)
'articulo.stock' ist wahrscheinlich eine Zeichenfolge. –
Ich kann nichts hinzufügen mehr als was @ Jean-FrançoisFabre gesagt hat. Es ist eindeutig ein String, so heißt es in der Fehlermeldung – WhatsThePoint
Vielen Dank! –