Python Forum

Full Version: Setter of class object
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am trying to override setter of a class in django. I have a class shown below
class Student:
details_done = models.BooleanField(default = False)


I want to call a function every time, the value of details_done is changed. Can anybody help me find out how can this be done.
Are you sure you want to do something whenever it's changed?  This sounds like something that should be done either in a validator or via a pre_save signal: https://docs.djangoproject.com/en/1.11/topics/signals/

Generally speaking, doing things just because something changed isn't a great idea.  What's "better" is making sure that the model is in a valid and complete state at the end of every transaction.