You are on page 1of 55

Search . . .

Working
with
Admin Panel

Session-7
simrantechmentor
Search . . .

Customer Website
01 Admin Panel

02 Customer View

simrantechmentor
Admin Panel Search . . .

01 Manage features

02 Settings

03 Dashboard

simrantechmentor
Example (Ecommerce) Search . . .

01 Add New Products, Categories

02 Update Price, Stock Availability,

03 Deactivate Customer or Seller

04 Statistics related to order (like recent orders, total orders, refund )

simrantechmentor
Example (Ecommerce) Search . . .

01 Order Updation

02 Check Payment Status

03 Add new user (Employee)

04 Delete user (Employee)

simrantechmentor
Customer View Search . . .

01 Use feature provided by Company

simrantechmentor
Search . . .

Django Admin
Search . . .

Django Admin Site


01 Django has automatic admin interface. (No need to write HTML,CSS, Javascript)

It reads metadata from your models to provide a quick, model-centric interrace where
02 trusted user can manage content on your site.

03 Note :- It is not intended for building your entire front end around.

simrantechmentor
Django Admin Site Search . . .

01 Admin site is automatically created by Django. This site is installed in your Django
project.

simrantechmentor
Django Admin Site Search . . .

01 URL is also registered automatically when you create your project.

simrantechmentor
Django Admin Site Search . . .

1. Open your podtalk project.


2. Run server : “py manage.py runserver”
3. Open browser : “https://127.0.0.1:8000/admin

simrantechmentor
Search . . .

Django User System


01 There are two type of Django User Classes.

02 User : Is a user authenticate himself by providing username and password then Django
recognize it as a user.

03 Anonymous : if a user just surf the website without any authentication then Django
recognizes him as an Anonymous User.

simrantechmentor
Search . . .

User class Types


Superuser :- The most powerful user with permissions to create, read, update and
01 delete data in the Django admin, which includes model records and other users.

Staff : - A user marked as staff can access the Django admin. But permissions to create,
02 read, update and delete data in the Django admin must be given explicitly to a user. By
default, a superuser is marked as staff.

active : All users are marked as active if they're in good standing. Users marked as
inactive aren't able to authenticate themselves, a common state if there's a pending
03
post-registration step (e.g. confirm email) or a user is banned and you don't want to
delete his data.

simrantechmentor
Search . . .

Group
Django also offers the concept of a Group class to grant a set of users the same set of
01 permissions without having to assign them individually.

For example, you can grant permissions to a group and then assign users to the group
02 to make permission management easier. In this manner, you can revoke or add
permissions in a single step to a set of users, as well as quickly give new users the same
permissions.

simrantechmentor
Search . . .

Create Superuser
Super user Search . . .

01 On terminal window : “py manage.py createsuperuser”

simrantechmentor
Django Admin Site Search . . .

1. Open your podtalk project.


2. Run server : “py manage.py runserver”
3. Open browser : “https://127.0.0.1:8000/admin
4. Type your user name and password and click on LogIn button

simrantechmentor
Django Home Page Search . . .

01 After you successful login. You will be redirected to home page of admin

simrantechmentor
Search . . .

Demo : User Feature


Search . . .

Demo : Group Feature


Search . . .

Demo : Register Model


to admin
Step 1. Register Models to Admin Search . . .

Open admin.py
Steps Import models
Register models to admin site

simrantechmentor
Django Admin Site Search . . .

1. Open your podtalk project.


2. Run server : “py manage.py runserver”
3. Open browser : “https://127.0.0.1:8000/admin
4. Type your user name and password and click on LogIn button

simrantechmentor
Django Admin Home Page Search . . .

simrantechmentor
Additional ‘s’ Search . . .

1. Django admin expects your classes to be named in the singular.


2. Django adds on an ‘s’ as standard way of pluralizing your class names.
3. In our example our model class name is Topics so Django add an ‘s’ and made it ‘Topicss’
4. Lets fix it.
5. Open models.py file and add sub class with the name of meta.

simrantechmentor
Refresh Django Admin Page Search . . .

simrantechmentor
Search . . .

Demo : Add new Topics


(Min 4)
Add New Topic Search . . .

simrantechmentor
Search . . .

Demo : Edit/Delete
Topics
Search . . .

Demo : Admin Interface


Customization
Current View of Model Search . . .

simrantechmentor
Show User defined value Search . . .

By default Django admin show Object info of Model on front page.


We can customize it and show user friendly value by overriding __str__() method.
Open models.py file.

simrantechmentor
Refresh Search . . .

simrantechmentor
Customize admin interface Search . . .

• In order to customize admin interface we need to create a new class for each model
and inherit it from “ModelAdmin” class.
• Also we need to change the register method.

simrantechmentor
Refresh Search . . .

simrantechmentor
Make display field editable Search . . .

• Use list_editable property to include field that you want to edit directly without
clicking on object detail page.

simrantechmentor
Refresh Search . . .

simrantechmentor
Search . . .

Demo : Show image in


Admin Interface.
Show Image on Admin interface Search . . .

• Add image field in list_display list.

simrantechmentor
Refresh Search . . .

• By default it will show path but not image.


• In order to show image we need to manage media files.

simrantechmentor
Search . . .

Manage media files.


01 In Django Media files are the files uploaded by users on the system. However, like static
files media files shouldn't be trusted.

02 There are always security concerns when dealing with user-uploaded content. Notably,
it’s important to validate all uploaded files. Django offers a large degree of flexibility to
manage user uploads.

simrantechmentor
Configuring Media files in Django Search . . .
• Open settings.py file of your project.

01 MEDIA_URL is the URL that will serve the media files.

02 MEDIA_ROOT is the path to the root directory where the files are getting stored.

simrantechmentor
Configuring Media files in Django Search . . .
• Open urls.py file of your project.

simrantechmentor
Update models.py file Search . . .
• Open models.py file of your app.

simrantechmentor
Update admin.py file Search . . .
• Open admin.py file of your app.

simrantechmentor
Refresh Search . . .

simrantechmentor
Search . . .

Demo : Sort Data


Sort Ascending Order Search . . .
• Open models.py file of your app.

simrantechmentor
Refresh Search . . .

simrantechmentor
Sort Descending Order Search . . .
• Open models.py file of your app.

simrantechmentor
Refresh Search . . .

simrantechmentor
Search . . .

Demo : Fetch Data from


Database.
Fetch Data from database Search . . .
• Open views.py file of your app.
• Delete all objects that you have created and add following code

simrantechmentor
Update html file Search . . .
• Open index.html file of your project.

simrantechmentor
Search . . .

THANK YOU
Kindly perform all in class exercise before coming to lab

END SLIDE

simrantechmentor
Contact No : 9878138788
Email : simran@webipher.com

You might also like