Here are my models:
class Ride(models.Model):
driver = models.ForeignKey('auth.User', related_name='rides_as_driver')
destination = models.CharField(max_length=100, default='')
leaving_time=models.TimeField()
leaving_date=models.DateField(default=datetime.date.today)
num_of_spots=models.IntegerField()
passengers=models.ManyToManyField('auth.User', related_name="rides_as_passenger")
mid_destinations = models.CharField(max_length=100, default='')
class PendingRequest(models.Model):
driver = models.ForeignKey('auth.User', related_name='driver_pending_requests')
passenger = models.ForeignKey('auth.User', related_name='passenger_pending_requests')
ride = models.ForeignKey(Ride)
As you can see - I have a Ride model with ManyToMany
field to auth.user
(passengers), ForeginKey
to auth.user
(driver), and also a PendingRequest model which has a ForeginKey
field to Ride.
Now, I want to to be able to delete a Ride object, have a custom code after the delete, and make sure that other models update accordingly.
For example, if I delete a Ride -> I want to have a custom code (send notification to passengers) -> and then delete the entries in the passenger table that have the deleted ride id in their ride
field, and also the PendingRequest entries which have the deleted ride id.
How should I go about this?