What is the proper way to check the previous value of a field before saving an object? (Using Django
Posted
by anonymous coward
on Stack Overflow
See other posts from Stack Overflow
or by anonymous coward
Published on 2010-05-07T20:30:36Z
Indexed on
2010/05/07
20:48 UTC
Read the original article
Hit count: 168
I have a Django Model with updated_by
and an approved_by
fields, both are ForeignKey fields to the built-in (auth) User models.
I am aware that with updated_by
, it's easy enough to simply over-ride the .save() method on the Model, and shove the request.user
in that field before saving.
However, for approved_by
, this field should only ever be filled in when a related field (date_approved
) is first filled in. I'm somewhat certain that I can check this logically, and fill in the field if the previous value was empty.
What is the proper way to check the previous value of a field before saving an object?
I do not anticipate that date_approved
will ever be changed or updated, nor should there be any reason to ever update the approved_by
entry.
UPDATE:
Regarding forms/validation, I should have mentioned that none of the fields in question are seen by or editable by users of the site. If I have misunderstood, I'm sorry, but I'm not sure how forms and validation apply to my question.
© Stack Overflow or respective owner