Skip to content

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

Open
@mostameen

Description

@mostameen

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions