๐ 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
- Superuser is created
- Admin panel authenticates user
- Registered models appear in admin
- Django auto-generates UI
- 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
| Operation | Action |
|---|---|
| Create | Add |
| Read | View |
| Update | Edit |
| Delete | Remove |
โ ๏ธ 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
- Create another superuser
- Add 5 student records
- Update multiple records
- Delete a record
- 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
Examples of Array Functions in PHP
Registration Form Using PDO in PHP
Inserting Information from Multiple CheckBox Selection in a Database Table in PHP
- Angular
- ASP.NET
- C
- C#
- C++
- CSS
- Dot Net Framework
- HTML
- IoT
- Java
- JavaScript
- Kotlin
- PHP
- Power Bi
- Python
- Scratch 3.0
- TypeScript
- VB.NET
