How to delete django superuser?

I want to delete all the superusers that I created in my django app.
But I don’t know the name of the superusers.

You can use the ORM to filter them out and delete them:

User.objects.filter(is_superuser=True).delete()

What is user here?
and where should I write User.objects.filter(is_superuser=True).delete() this command?

Okay, I think you are missing too much knowledge to answer on a forum post. Have you done the Django tutorial?

yes.
You have to tell me.
I’ve done one project using django too.
Is Users app_name or project name?
How do you know if I’m using the built-in User model or I’ve extended it using abstractUser or abstractBaseUser?

It’s the model name. Recall filtering models from part two of the tutorial: Writing your first Django app, part 2 | Django documentation | Django

I don’t know. Use whichever model name is appropriate.

from django.contrib.auth.models import User

If you imported above thing in your py file this will take default User model from django auth

if you want extended User model

from django.contrib.auth.models import AbstractUser

import AbstractUser using above line and you can modify User model by abstracting built in User model . Like this (Example):-

class User(AbstractUser):
    #Custom fields you can add from here 
    myCustomField=models.CharField(max_length=225)
    USERNAME_FIELD = 'email'  #making email as user name
    REQUIRED_FIELDS = []

There are plenty of way to customise base User

  • We can abstract BaseManager also which will deal methods like createsuperuser , createuser etc .

For that Please see suggestions from @ adamchainz
Go through the basics . Happy learning :slight_smile:

1 Like