Skip to content
Snippets Groups Projects
signals.py 556 B
from django.db.models.signals import post_save
from django.dispatch import receiver
from program.models import Note, TimeSlot


@receiver(post_save, sender=TimeSlot)
def attach_note(sender, instance, created, **kwargs):
    if created:
        note = Note.objects.create(timeslot=instance)

        show = instance.schedule.show

        note.contributors.set(show.hosts.values_list("id", flat=True))
        note.language.set(show.language.values_list("id", flat=True))
        note.topic.set(show.topic.values_list("id", flat=True))

        note.save()