Access the form that caused a post_save [Django]

215 views Asked by At

Is there a way I can access the form that caused a post_save?

The use case is that I have a field (a checkbox) that isn't attached to a particular model, but it's an extra field in the form itself.

I want to know whether the field was checked or unchecked when the form got saved and the model stored, and imho the post_save signal is a good place to put the logic that should process that extra field.

I'm also open to suggestions where else I could put that piece of code.

1

There are 1 answers

4
Chris On

post_save won't know anything about any form that might have caused the model change.

If you want to access that checkbox value you need to do it in the form class itself. I would probably override the clean() method of the form, and check for the checkbox value in cleaned_data['checkbox_field'] there, and then do whatever you need to with it.