0
我有這個錯誤,你能幫我嗎?您需要從「Articulo」模型的「Pedido」 - 「庫存」模型中減去「數量」值,然後保存庫存結果。不支持的操作數類型(s) - =:'str'和'int'
管線: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'是一個字符串,可能。 –
我不能添加任何比Jean-FrançoisFabre所說的更多的東西。它顯然是一個字符串,它在錯誤消息 – WhatsThePoint
中這麼說,非常感謝! –