Skip to content

Instantly share code, notes, and snippets.

@maxwellamaral
Forked from maxwellcc/model.py
Created September 6, 2022 12:41
Show Gist options
  • Save maxwellamaral/b3b956b4dd8fdda2face1ae3f37571e5 to your computer and use it in GitHub Desktop.
Save maxwellamaral/b3b956b4dd8fdda2face1ae3f37571e5 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