So, I have a model something like this
class Blog(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
posted_by = models.ForeignKey(User, on_delete=models.CASCADE, null=True)
def delete(self, *args, **kwargs):
# to do before delete
super().delete(*args, **kwargs)
I want to delete all Blog objects related to User when the User is deleted. It is working but its deleting object without calling overridden delete function. I want to delete the model through the overridden delete function coz i have something to do before actually deleting the object. If it is not possible, do suggest any other way to do it.
It should still be possible with pre_delete
signal:
@receiver(pre_delete, sender=Blog)
def my_pre_delete_process_for_blog(sender, instance, **kwargs):
...
From the docs:
Note that the delete() method for an object is not necessarily called when deleting objects in bulk using a QuerySet or as a result of a cascading delete. To ensure customized delete logic gets executed, you can use pre_delete and/or post_delete signals.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments