Check box in Django admin run a Python function on save without a BooleanField
You can add any arbitrary fields to a form: they need to be form fields (eg forms.BooleanField) but as long as they don't also exist on the model they won't be saved.
You can then take any action you like in the form's clean() method, or in the modeladmin's save_form method.
Is there a way to have a check box appear in Django admin, but instead of associating it with a BooleanField, having it run a function if it is / is not checked upon save? I don't need to store a Boolean in the database, but may need to store something depending on other fields, and whether the check box was checked.
In particular, I would like to store a ForeignKey if the check box was just checked, empty it (set ForeignKey to null) if the check box was just unchecked, and do nothing it the check box state stayed the same. I don't want to display what this ForeignKey is to the user, just set it or delete it behind the scenes.