Created
May 27, 2020 11:52
-
-
Save maxwellcc/c4f43a88c25e0f9a8533f2c8ad735d92 to your computer and use it in GitHub Desktop.
Django: detectando mudanças nos campos do model
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def save(self, *args, **kwargs): | |
# Detectando mudanças em alguns campos | |
old = Notification.objects.filter(pk=getattr(self, 'pk', None)).first() | |
if old: | |
# Se o campo number tiver sido modificado, limpar os campos | |
if old.number != self.number: | |
self.file = None | |
self.download_success = False | |
self.download_date_time = None | |
self.log = '' | |
super(Notification, self).save(*args, **kwargs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment