Hi all,
I have the following models:
class Sale(models.Model):
location= models.CharField(max_length=300)
price = models.DecimalField(decimal_places=2, max_digits=12)
class Product(models.Model):
product = models.CharField(max_length=300)
price = models.DecimalField(decimal_places=2, max_digits=12)
that I’m trying to update with:
discounted_price = Product.objects.filter(product=product).first()
completed_sale= Sale.objects.filter(id=id).first()
best_price = getattr(discounted_price, "price")
completed_sale.price =best_price
completed_sale.save(update_fields=["price "])
Basically I’m retrieving the price from a product and updating the sale price, both models have a price field of type DecimalField(decimal_places=2, max_digits=12)
but I can’t manage to update the sale price with completed_sale.price =best_price
IT should be pretty straightforward but the field is not updated. I have also some other text fields in the 2 models that are updated without any issues following this structure.
Do I have to somehow cast the DecimalField or am I missing something?
Thanks in advance