Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't update constance field programatically from the signal handler #515

Open
mostameen opened this issue Mar 24, 2023 · 1 comment
Open

Comments

@mostameen
Copy link

mostameen commented Mar 24, 2023

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
@Mogost
Copy link
Member

Mogost commented Jul 12, 2024

Probably connected with #442

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants