diff --git a/app/recipes/apps.py b/app/recipes/apps.py index 683b24f..633e096 100644 --- a/app/recipes/apps.py +++ b/app/recipes/apps.py @@ -4,3 +4,6 @@ class RecipesConfig(AppConfig): default_auto_field = "django.db.models.BigAutoField" name = "recipes" + + def ready(self): + import recipes.signals diff --git a/app/recipes/signals.py b/app/recipes/signals.py new file mode 100644 index 0000000..e04b1ff --- /dev/null +++ b/app/recipes/signals.py @@ -0,0 +1,8 @@ +from django.db.models.signals import post_save +from django.dispatch import receiver +from .models import Recipe, Updated_recipe + +@receiver(post_save, sender=Recipe) +def create_updated_recipe_on_recipe(sender, instance, created, **kwargs): + if created: + Updated_recipe.objects.create(status='new', recipe=instance) \ No newline at end of file