How to pass all field names to when_any argument of django-lifecycle hook

Viewed 37

I am using django-lifecycle to create a function in a model to be run when any input is changed. I'm doing this using the before_update hook, e.g.

@hook("before_update", when_any=list_of_fields, has_changed=True)
    def do_something(self):
        do something here...

I am trying to pass all of the field names to the when_any argument but struggling because the hook argument cannot use self to get this. For example doing:

@hook("before_update", when_any=[f.name for f in self._meta.get_fields()], has_changed=True)
    def do_something(self):
        do something here...

gives the NameError NameError: name 'self' is not defined.

Is there a way to get all of the model field names in another way from within the model class?

0 Answers
Related