Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8659835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:06:11+00:00 2026-06-12T16:06:11+00:00

I have the following model: from django.db import models from django.contrib.auth.models import User class

  • 0

I have the following model:

from django.db import models
from django.contrib.auth.models import User


class Profile(models.Model):
    user = models.OneToOneField(User)
    # ...

    def __unicode__(self):
        return u'%s %s' % (self.user.first_name, self.user.last_name)

When using the Django admin to delete the user, the profile gets deleted as well, which is what I want. However, when using the Django admin to delete the profile, the user does not get deleted, which is not what I want. How can I make it so that deleting the profile will also delete the user?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T16:06:12+00:00Added an answer on June 12, 2026 at 4:06 pm

    Since Profile links to User, it is the dependent model in the relationship. Therefore when you delete a user, it deletes all dependent models. However when you delete a profile, since User does not depend on profile, it is not removed.

    Unfortunately, according to on_delete Django docs, there is no on_delete rule which deletes the parent relations. In order to do that, you can overwrite the Profile‘s delete method:

    class Profile(models.Model):
        # ...
    
        def delete(self, *args, **kwargs):
            self.user.delete()
            return super(self.__class__, self).delete(*args, **kwargs)
    

    Then when doing:

    Profile.objects.get(...).delete()
    

    will also delete the profile’s user. However the delete method will not be called when deleting profiles using querysets (which is what is called in Django Admin) since then Django uses SQL DELETE to delete objects in bulk:

    Profile.objects.filter(...).delete()
    

    In that case, as recommended by Django docs, you will have to use post_delete signal (docs).

    from django.dispatch import receiver
    from django.db.models.signals import post_delete
    
    @receiver(post_delete, sender=Profile)
    def post_delete_user(sender, instance, *args, **kwargs):
        if instance.user: # just in case user is not specified
            instance.user.delete()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following setup. from django.db import models from django.contrib.auth.models import User class Event(models.Model):
I have the following: from django.contrib.auth.models import User class ClientDetails(models.Model): created_by = models.ForeignKey(User) ...
I have the following model setup. from django.db import models from django.contrib.auth.models import User
I have the following model in Django: from django.db import models class User(models.Model): pen_name
Suppose I have the following Event model: from django.db import models import datetime class
I want a nice convenient attribute to do the following: from django.contrib.auth.models import User
Let's assume we have following models: from django.db import models class Foo(models.Model): name =
I have the following model: from django.db import models import datetime class Club(models.Model): establishment
I have the following model. from django.db import models class Client(models.Model): postcode = models.CharField(max_length=10)
I have the following multi-table inheritance situation: from django.db import Models class Partner(models.Model): #

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.