I am trying to save the value of a field in an instance variable on my Video model and then use this instance variable in a post_save
signal receiver to see if the value of the field has changed.
I am going off of this Stack Overflow answer:
https://stackoverflow.com/a/36722021/
Here is my Video model:
class Video(models.Model):
approval = models.BooleanField(default=True)
def __init__(self, *args, **kwargs):
super(Video, self).__init__(*args, **kwargs)
self.__original_approval = self.approval
Here is my post_save
signal receiver:
@receiver(post_save, sender=Video)
def handle_video_save(sender, **kwargs):
video = kwargs.get('instance')
previous_approval = video.__original_approval
# check if value has changed...
This is the error I'm getting:
AttributeError: 'Video' object has no attribute '__original_approval'
While debugging, I have found that the instance variable can be accessed this way in my post_save
signal receiver:
previous_approval = video._Video__original_approval
So, using video._Video__original_approval
works, but I'm wondering why am I unable to access the instance variable, as I've seen in other answers on Stack Overflow, with video.__original_approval
?
I'm using Django 1.11.20 and Python 3.6.6.