django-constance
django-constance copied to clipboard
Can't update constance field programatically from the signal handler
Describe the problem
Trying to update a constance field based on the value of another field
Let's say we have 2 fields title & slug .. the point is whenever title is updated, slug must be updated to the same value without spaces
receiver(config_updated)
def constance_updated(sender, key, old_value, new_value, **kwargs):
print(key, old_value, new_value, sep=" - ")
if key == "title" and new_value:
try:
setattr(sender, "slug", new_value.replace(" ", ""))
except Exception as e:
print(str(e))
Here's what i get when i print the updated fields and their values
title - old title - new title
slug - - newtitle
slug - newtitle -
Seems that the slug value is updated already , but then updated again to the old value !
System configuration
- Django version: 4.1.7
- Python version: 3.9.5
- Django-Constance version: 2.9.1
Probably connected with #442