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 7547399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:26:37+00:00 2026-05-30T09:26:37+00:00

I created UserProfile (extends from User) and written to settings.py AUTH_PROFILE_MODULE = ‘mainapp.UserProfile’. When

  • 0

I created UserProfile (extends from User) and written to settings.py

 AUTH_PROFILE_MODULE = 'mainapp.UserProfile'.

When I delete UserProfile (from admin area) I would delete also User item.

I try delete user so self.user.delete(), but method delete (in UserProfile) don’t call. Why ?

This is my code:

class UserProfile(models.Model):
    avatar = models.ImageField(upload_to = settings.PATH_AVATARS, blank=True)
    url = models.URLField(blank=True)
    user = models.OneToOneField(User)

    def __unicode__(self):
        return self.user.username

    def delete(self, *args, **kwargs):
        self.user.delete()
        super(UserProfile, self).delete(*args, **kwargs)
  • 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-05-30T09:26:38+00:00Added an answer on May 30, 2026 at 9:26 am

    First, to answer why “delete()” is not called from the admin. This statement is:

    1. True in the case of deleting objects from the list view, ie. /admin/auth/user/ check some boxes then click Actions -> delete), this is because the delete() method of a queryset is called,
    2. Wrong in the case of deleting an object from the change_form, ie. /admin/auth/user/1/ click on delete, this is where the delete() method of the object is called

    That said, _delete signals are well supported. Here is how you can use it:

    from django.db.models import signals
    
    def delete_user(sender, instance=None, **kwargs):
        try:
            instance.user
        except User.DoesNotExist:
            pass
        else:
            instance.user.delete()
    signals.post_delete.connect(delete_user, sender=UserProfile)
    

    This is how i tested it:

    In [1]: from django.contrib.auth.models import User; from testapp.models import UserProfile; User.objects.all().delete(); UserProfile.objects.all().delete()
    
    In [2]: user=User(username='foo'); user.save()
    
    In [3]: profile=UserProfile(user=user); profile.save()
    
    In [4]: UserProfile.objects.all().delete()
    
    In [5]: User.objects.all()
    Out[5]: []
    

    Of course, this also works when the delete() method of the object is called:

    In [1]: from django.contrib.auth.models import User; from testapp.models import UserProfile; User.objects.all().delete(); UserProfile.objects.all().delete()
    
    In [2]: user=User(username='foo'); user.save()
    
    In [3]: profile=UserProfile(user=user); profile.save()
    
    In [4]: profile.delete()
    
    In [5]: User.objects.all()
    Out[5]: []
    

    Note that because of cascade delete, this works both ways:

    In [1]: from django.contrib.auth.models import User; from testapp.models import UserProfile; User.objects.all().delete(); UserProfile.objects.all().delete()
    
    In [2]: user=User(username='foo'); user.save()
    
    In [3]: profile=UserProfile(user=user); profile.save()
    
    In [4]: user.delete()
    
    In [5]: User.objects.all()
    Out[5]: []
    
    In [6]: UserProfile.objects.all()
    Out[6]: []
    

    If you need to know more about signals, refer to Django’s extensive documentation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two models: UserProfile (extended from user) and Cv . I created another
I'm trying to test that a UserProfile model is created as a new User
Hey, I've a database already created. Now I've updated UserProfile with: class UserProfile(models.Model): user
I've extended the standard Django User model with a UserProfile, and created a OneToOne
Created .NET WCF service, tested it - works. Generated schemas from Data and service
I created a program using dev-cpp and wxwidgets which solves a puzzle. The user
I created an Interop user control in VS2005. When the user control is shown
I have an extended UserProfile model in django: class UserProfile(models.Model): user = models.ForeignKey(User, unique=True)
A user logins into the SharePoint site we have created using their email address
I have the following two models: class Position(models.Model): position = models.CharField(max_length=100) class UserProfile(models.Model): user

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.