0% found this document useful (0 votes)
2 views

Django - admin interface

This document outlines the steps for creating a Django project and app, specifically focusing on setting up an Admin interface for managing an Employee database. It includes instructions for defining the Employee model, registering it in the admin interface, making migrations, creating a superuser, and running the server. Additionally, it details how to display and manage the Employee table with filtering and search capabilities in the admin interface.

Uploaded by

126003020
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Django - admin interface

This document outlines the steps for creating a Django project and app, specifically focusing on setting up an Admin interface for managing an Employee database. It includes instructions for defining the Employee model, registering it in the admin interface, making migrations, creating a superuser, and running the server. Additionally, it details how to display and manage the Employee table with filtering and search capabilities in the admin interface.

Uploaded by

126003020
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

CSE 304

PYTHON PROGRAMMING WITH WEB


FRAMEWORKS
UNIT – 4

Django - Admin Interface


Dr.S. Priya/AP-III/ICT

CSE
CSE 304
304 Python
Python programming
programming
Django with Database

• Types of intractive interface for data base

– Admin GUI
– Shell interface
– django Forms (web interface)

• Create Project
django-admin.py startproject adminproj
• Create app
python manage.py startapp adminapp

in Settings.py
include adminapp

14-Oct-24 CSE
CSE 304
304 Python
Python programming
programming 2
Design a Employee table

Include the following class definition in models.py(adminapp)

class Employee(models.Model):
empid=models.IntegerField()
empname=models.CharField(max_length=20)
empsalary=models.InegerField()
empaddress=models.CharField(max_length=50)

CSE 313 Cryptography and Network Security


Programming in C
14-Oct-24 CSE
CSE304304Python
Pythonprogramming
programming By Dr.S.Priya 3
Register Employee table

In admin.py file,

from .models import Employee


admin.site.register(Employee) # only firtst time user registeration

CSE 313 Cryptography and Network Security


Programming in C
14-Oct-24 CSE
CSE304304Python
Pythonprogramming
programming By Dr.S.Priya 4
Make migrations

Create and execute table query (in terminal window)

• python manage.py makemigrations


• Python manage.py migrate

CSE 313 Cryptography and Network Security


Programming in C
14-Oct-24 CSE
CSE304304Python
Pythonprogramming
programming By Dr.S.Priya 5
Create super user

Create super user in terminal window


• python manage.py createsuperuser
– Username

– Email

– Password

CSE 313 Cryptography and Network Security


Programming in C
14-Oct-24 CSE
CSE304304Python
Pythonprogramming
programming By Dr.S.Priya 6
runserver

• python manage.py runserver


– 127.0.0.1:8000/admin

ü In admin interface login with username and pwd.

ü Insert recorde in the table in admin page

CSE 313 Cryptography and Network Security


Programming in C
14-Oct-24 CSE
CSE304304Python
Pythonprogramming
programming By Dr.S.Priya 7
Display the table content with filtering and search operation in admin.py

from .models import Employee


#admin.site.register(Employee) (not needed after first time)
@admin.register(Employee)
class Employeeadmin(admin.ModelAdmin):
list_display=('empid','empname','empsalary','empaddress')
list_filter=('empsalary',)
ordering=('empname',)
search_fields=('empname',)

CSE 313 Cryptography and Network Security


Programming in C
14-Oct-24 CSE
CSE304304Python
Pythonprogramming
programming By Dr.S.Priya 8

You might also like