Skip to content

Instantly share code, notes, and snippets.

@maxwellcc
Created May 27, 2020 11:52
Show Gist options
  • Save maxwellcc/c4f43a88c25e0f9a8533f2c8ad735d92 to your computer and use it in GitHub Desktop.
Save maxwellcc/c4f43a88c25e0f9a8533f2c8ad735d92 to your computer and use it in GitHub Desktop.
Django: detectando mudanças nos campos do model
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