I have a task that creates a new instance of a model and I want a signal to trigger something else.
The documentation on signals says the post_save signal is sent when a model.save() is executed, but in my testing it appears that only web POST as from a form trigger that signal.
The part of my celery task that successfully creates a record does not send a signal, either with objscts.create or modelsave()
# Save prediction to database Predictions table
p = Predictions(sepal_length=sepal_length,
sepal_width=sepal_width,
petal_length=petal_length,
petal_width=petal_width,
prediction=prediction_name)
p.save()
# Predictions.objects.create(sepal_length=sepal_length,
# sepal_width=sepal_width,
# petal_length=petal_length,
# petal_width=petal_width,
# prediction=prediction_name)
The signal is caught by
@receiver(post_save, sender=Predictions)
def post_save_pcreate(sender, instance, created, **kwargs):
print()
print('OOOOOOOOOOOOOOOOOOOOOOO Review.signals.Predictions.post_save signal')
print()
and I see this OOO only when posting a new record in Predictions in the admin pages or the application web page, not with the task, although Prediction records are created in all three ways.
Is there a way around this?