I am trying to update a status field via signals but get a max recursion error. Using django 4.1.1.
models.py
class Product(models.Model):
# ….
PRODUCT_STATUS = (
('P', _('Preparation')),
('S', _('Sold')),
('T', _('Shipped')),
)
status = models.CharField(max_length=1, null=True,
choices=PRODUCT_STATUS, default='P')
price_sold = models.DecimalField(
_('Price Sold'), max_digits=10, decimal_places=2, blank=True, null=True)
#…
signals.py
@receiver(post_save, sender=Product)
def post_save_product_set_status_sold_if_price_sold(sender, instance, created, **kwargs):
if instance.price_sold != None:
instance.status = 'S'
instance.save(update_fields=['status'])
I get the following error when saving
RecursionError at /admin/products/product/14/change/ maximum recursion depth exceeded while calling a Python object
Can somebody help?