Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I delete all user data when deleting profile on Django using signals.py

how can I delete all user data when deleting a user profile on Django using signals.py? I am trying to delete a custom user model using Django and when the profile is deleted I want to delete all data of that user using signals.py how can I create it?

@receiver(post_delete, sender=models.Profile_user)
def delete_auth_user_model_handler(sender, instance, *args, **kwargs):
    user_instance = instance.user
    user_instance.delete()

I want to delete blogs of the user-written when the profile is deleted

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You could just declare your models as ForeignKeys to your user. This way when you delete the user , everything associated with it will be deleted:

class Blogs(models.Model):
author= models.ForeignKey(User, on_delete=models.CASCADE, blank=True, null=True, default=None)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading