Django

Create a Superuser and Perform Database Operations through Admin Panel

๐Ÿ“Œ Introduction

The Django admin panel can only be accessed by authorized users.

๐Ÿ‘‰ For this, we create a superuser, who has:

  • full permissions
  • access to admin panel
  • ability to perform all database operations

๐ŸŽฏ Program Statement

๐Ÿ‘‰ Create a superuser and perform database operations through admin panel.


๐Ÿง  Concept

This program involves:

  • creating superuser
  • logging into admin
  • performing CRUD operations

โš™๏ธ Step 1: Create Superuser


๐Ÿ”น Command:

python manage.py createsuperuser

๐Ÿ”น Enter Details:

Username: admin
Email: admin@example.com
Password: ********

๐Ÿ‘‰ Password will be hidden while typing


โœ… Output:

Superuser created successfully.

โš™๏ธ Step 2: Run Server

python manage.py runserver

โš™๏ธ Step 3: Open Admin Panel

๐Ÿ‘‰ Open:

http://127.0.0.1:8000/admin/

โš™๏ธ Step 4: Login

๐Ÿ‘‰ Enter credentials:

  • Username: admin
  • Password: ********

๐ŸŒ Step 5: Admin Dashboard

After login, you will see:

MYAPP
Students

โš™๏ธ Step 6: Perform Database Operations


๐Ÿ”น 1. Add Record

๐Ÿ‘‰ Click Students โ†’ Add

Fill form:

Name: Charlie
Age: 20
Course: BBA
Email: charlie@example.com

๐Ÿ‘‰ Click Save


๐Ÿ”น 2. View Records

๐Ÿ‘‰ You will see all student records in list format


๐Ÿ”น 3. Update Record

๐Ÿ‘‰ Click any record
๐Ÿ‘‰ Modify values

Example:

Age: 26

๐Ÿ‘‰ Click Save


๐Ÿ”น 4. Delete Record

๐Ÿ‘‰ Select record
๐Ÿ‘‰ Click Delete

๐Ÿ‘‰ Confirm deletion


๐Ÿง  How It Works

  1. Superuser is created
  2. Admin panel authenticates user
  3. Registered models appear in admin
  4. Django auto-generates UI
  5. User performs CRUD operations

๐Ÿ”ฅ Key Concepts


Create Superuser

python manage.py createsuperuser

Admin Login URL

/admin/

Permissions

Superuser has:

  • add
  • change
  • delete
  • view

Admin Operations

OperationAction
CreateAdd
ReadView
UpdateEdit
DeleteRemove

โš ๏ธ Common Errors


โŒ Command not recognized

๐Ÿ‘‰ Run inside project folder


โŒ Password too weak

Django may show warning


โŒ Cannot login

Check:

  • username/password correct
  • superuser created

โŒ Admin not accessible

Check:

'django.contrib.admin'

in INSTALLED_APPS


โŒ Model not visible

Ensure:

admin.site.register(Student)

๐Ÿงช Practice Questions

  1. Create another superuser
  2. Add 5 student records
  3. Update multiple records
  4. Delete a record
  5. Explore admin filters and search

๐ŸŽค Viva Questions & Answers


1. What is a superuser in Django?

A superuser is an admin user with full permissions to manage the application.


2. Which command is used to create superuser?

python manage.py createsuperuser


3. What is the admin panel URL?

/admin/


4. What operations can be performed in admin?

Add, view, update, and delete records.


5. Why do we need a superuser?

To securely access and manage the admin panel.


6. Can normal users access admin?

Only if they are given staff permissions.


7. What happens if superuser is not created?

You cannot log into admin panel.


8. What is CRUD?

Create, Read, Update, Delete operations.


9. Is admin panel automatically generated?

Yes, Django auto-generates it for registered models.


10. Why is admin panel important?

It allows quick database management without coding frontend.


๐Ÿ”— Navigation

๐Ÿ‘‰ Next Post: Create a User Registration Page using Django Built-in User Model
๐Ÿ‘‰ Back to List: Django Programs (60 Questions with Solutions)


Further Reading

Introduction to Django Framework and its Features

Django Practice Exercise

Examples of Array Functions in PHP

Basic Programs in PHP

Registration Form Using PDO in PHP

Inserting Information from Multiple CheckBox Selection in a Database Table in PHP

programmingempire

princites.com

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *