I have following models:
class Meal(models.Model):
name_text = models.CharField(max_length=200)
class Menu(models.Model):
meals = models.ManyToManyField(Meal)
When I delete a meal I would like to raise an error message like "You can't delete this meal because it is used in a menu", when the meal is referenced in a menu.
At the moment when I call meal.delete()
the meal is just deleted.
Is there an on_deleted
attribute for the ManyToMany-Relationships similar to the ForeignKey Relationship?
Or do I have to go through all Menu
s and check if one references the meal
?