I have a model that I want to implement a signal's post_save on. Here's my model:
class Answer(models.Model):
question = models.ForeignKey(
Question,
related_name='answers_list',
on_delete=models.CASCADE
)
answer = models.CharField(max_length=500)
additional = models.CharField(
max_length=1000,
null=True,
blank=True,
default=None
)
created_at = models.DateTimeField(auto_now_add=True)
In order to catch the creation of the object, I've created a new signals.py file with the following context:
from django.dispatch import receiver
from django.db.models.signals import post_save
from core.models import Answer
@receiver(post_save, sender=Answer)
def answer_question(sender, instance, **kwargs):
print("CAUGHT A SIGNAL")
print(instance.question.sentence, instance.answer)
But when I create a new answer it doesn't seem to trigger the signal (I'm creating it via front-end, since I'm using django-rest-framework). I don't see anything in my console other than the POST method that's going to my API.
What's wrong?