0

Use cases: I want to programmatically access the value of a form field prior to the update, for one of the following scenarios (just 2 examples, to illustrate the case)

a) I want to detect if the original value of a field has been changed in the form, before it's saved in the database b) I want to detect / prevent changing the field value in a very specific way, e.g. if a field value is set to "Approved", it should never change back to "Pending approval", etc.

Constraint: Ideally, I would prefer not to do another trip to the database (to check for the old value), for performance reasons.

j-i-l
  • 10,281
  • 3
  • 53
  • 70
  • You could make a separate hidden version of each field that retains the original value. – John Gordon Mar 27 '21 at 23:35
  • 1
    If you work with a ModelForm: https://stackoverflow.com/a/12807227/1622937 – j-i-l Mar 27 '21 at 23:42
  • Thank you! This looks exactly what I was looking for, will check and mark as answered – user6131524 Mar 27 '21 at 23:57
  • 1
    @user6131524 you are welcome. Best is to mark it as a duplicate of [Django ModelForm Validation](https://stackoverflow.com/questions/12806771/django-modelform-validation) – j-i-l Mar 28 '21 at 00:06

0 Answers0