Created
April 13, 2020 07:17
-
-
Save Natim/31f3fb9e7060b17146b13801ade90270 to your computer and use it in GitHub Desktop.
Register m2m changed event.
This file contains hidden or 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
# Voir https://docs.djangoproject.com/fr/3.0/ref/signals/#m2m-changed pour plus d'infos | |
@receiver(m2m_changed, sender = VisiteMedicale.animaux.through) | |
def visite_medicale_save_action(sender, instance, **kwargs): | |
if reverse: | |
# Cas de popi.visite_medicale_set.remove(sterilisation_20200413) | |
animaux = [instance] | |
visite_medicale = model.objects.get(pk__in=pk_set) | |
else: | |
# Cas de sterilisation_20200413.animaux.add(Popi) | |
animaux = model.objects.filter(pk__in=pk_set).all() | |
visite_medicale = instance | |
type_visite = visite_medicale.type_visite | |
print("Type visite : " + type_visite + "\n") | |
sys.stdout.flush() | |
if type_visite in (TypeVisiteVetoChoice.STE.name, TypeVisiteVetoChoice.VAC.name): | |
sys.stdout.flush() | |
for animal in animaux: | |
print("Animal : " + animal.nom + "\n") | |
sys.stdout.flush() | |
if type_visite == TypeVisiteVetoChoice.STE.name: | |
animal.sterilise = OuiNonChoice.OUI.name | |
elif instance.type_visite == TypeVisiteVetoChoice.VAC.name: | |
animal.vaccine = OuiNonChoice.OUI.name | |
animal.date_dernier_vaccin = instance.date | |
animal.save() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment