SlideShare ist ein Scribd-Unternehmen logo
1 von 61
Administration

  Rashi Dhing
A blog web application


 •   We need to have an interface to

     •   post, delete and modify articles

     •   moderate comments

     •   manage authorized writers and viewers

 ➡   We need an administration interface
Why having an administration interface

•   Inspecting data
    see what the database contains

•   Managing acquired data
    insert, modify and delete database records

•   Managing users
    define who can access your application

✓   All of these should be accessible for non technical users
How to build such an administrator interface?




➡   We could build the administrator interface from scratch

๏   It's painfully, boring and repetitive to build it

✓   With Django “batteries are included”
Django provides




✓   An optional, pluggable and customizable admin interface ...




                                        ... and it looks really good!
Activate the admin interface
  for your Django project
Step 1 - Modify the project settings
 ...                                                     setting.py
 INSTALLED_APPS = (
       'django.contrib.auth',
       'django.contrib.contenttypes',
       'django.contrib.sessions',
       'django.contrib.sites',
       'django.contrib.messages',
       'django.contrib.staticfiles',
       'WebDirectory',
       # Uncomment the next line to enable the admin:
       'django.contrib.admin',
       # Uncomment the next line to enable admin documentation:
       # 'django.contrib.admindocs',
 )
 ...
Step 2 - Re-synchronize the database


$ python manage.py syncdb
Step 3 - Modify the project URL Dispatcher



                                                               urls.py
from django.conf.urls.defaults import patterns, include, url


urlpatterns = patterns('',
    (r'^webdirectory/', include('WebDirectory.urls')))


from django.contrib import admin
admin.autodiscover()
urlpatterns += patterns('',(r'^admin/', include(admin.site.urls)))
The admin interface is ready!
The admin interface is ready!

                                URL of the admin site
The admin interface is ready!

                                 URL of the admin site




                                So far, you can login as the
                                superuser created during
                                the first database sync
Activate the admin interface
 for the WebDirectory app
Step 1 - Create the admin.py file in WebDirectory


             WebDirectory/
                 __init__.py
                 models.py
                 test.py
                 views.py
                 urls.py
                 admin.py
                 templates/
                 static/
Step 2 - Modify admin.py

                                                 WebDirectory/admin.py
 from WebDirectory.models import Entry
 from django.contrib import admin
   
   
   
   
   
   


 admin.site.register(Entry)
Step 2 - Modify admin.py

                                                 WebDirectory/admin.py
 from WebDirectory.models import Entry
 from django.contrib import admin
   
   
   
   
   
   


 admin.site.register(Entry)



                         makes the Entry data model available
                         on the admin interface
Admin
WebDirectory data models
From WebDirectory admin you can
From WebDirectory admin you can




             get the list of records
From WebDirectory admin you can


                                       add records


             get the list of records
From WebDirectory admin you can


                                       add records


             get the list of records
From WebDirectory admin you can


                                             add records


                   get the list of records




  modify records
From WebDirectory admin you can


                                                add records


                      get the list of records




     modify records




delete records
Creating a dedicated administrator
        for WebDirectory
The superuser administrator has all powers




•   Create, modify and delete users

•   Insert, modify, delete records from every application
How to be more restrictive?



✓   We want to create an administrator for the WebDirectory
    application only

    •   A dedicated user admin named John Doe - login: jdoe

    •   With the administrative privileges to create, modify and
        delete records in WebDirectory only
Create the John Doe admin user
Admin
login and password
login and password


user’s information
login and password


                      user’s information



staff = admin power
login and password


                          user’s information



staff = admin power




                      give all administrative
                      permissions for WebDirectory
What the administrator can do
What the administrator can do



       After logging in as jdoe ...
What the administrator can do



       After logging in as jdoe ...




                    ... John Doe can administrate WebDirectory only
Customize the admin interface
How to customize the admin interface?

✓   By editing the admin.py

•   The class ModelAdmin is the representation of the models
    in the admin interface

•   Changing the admin options

      1. create a new model admin object
        class EntryAdmin(admin.ModelAdmin):
               ...

      2. register this new admin object
        admin.site.register()
Task 1 - Customizing the interface for editing a record




Default
Task 1 - Customizing the interface for editing a record




Default
                                                Finally


 fields grouped
 in fieldsets
Task 1.1 - Modify the field order when editing a record




Default
Task 1.1 - Modify the field order when editing a record




Default
                                              After


  fields reordered
Task 1.1 - Editing admin.py


                                                   WebDirectory/admin.py

 from WebDirectory.models import Entry
 from django.contrib import admin
     
   
   
   
   
   


 Class EntryAdmin(admin.ModelAdmin):
 
   
   fields = ['name', 'image', 'mimeType', 'webpage']


 admin.site.register(Entry,EntryAdmin)
Task 1.2 - Splitting fields into field sets




Now
Task 1.2 - Splitting fields into field sets




Now
                                            Finally


    fields grouped
    in fieldsets
Task 1.2 - Editing admin.py


                                                   WebDirectory/admin.py
 from WebDirectory.models import Entry
 from django.contrib import admin
     
   
   
   
   
   


 Class 
       Class EntryAdmin(admin.ModelAdmin):
     fieldsets = [
             ('File info', {'fields': ['name','webpage']}),
             ('Upload image', {'fields': ['image','mimeType']})]
 
   
   
 admin.site.register(Entry, MyAdmin)
Task 2 - Customizing the interface for listing all records




Default
Task 2 - Customizing the interface for listing all records




Default
                                                   Finally




   Multiple attributes displayed
Task 2 - Customizing the interface for listing all records




Default
                                                   Finally
                             search by name




   Multiple attributes displayed
Task 2 - Customizing the interface for listing all records




Default
                                                        Finally
                             search by name




   Multiple attributes displayed              filter by MIME type
Task 2.1 - Changing the record list output




Default
Task 2.1 - Changing the record list output




Default
                                             After




        Multiple attributes displayed
Task 2.1 - Editing admin.py

                                                   WebDirectory/admin.py
 from WebDirectory.models import Entry
 from django.contrib import admin
     
   
   
   
   
   


 Class 
       Class EntryAdmin(admin.ModelAdmin):
     fieldsets = [
             ('File info', {'fields': ['name','webpage']}),
             ('Upload image', {'fields': ['image','mimeType']})]


     list_display = ('name', 'mimeType', 'webpage')
 
   
   
 admin.site.register(Entry, MyAdmin)
Task 2.2 - Adding filter and search




 Now
Task 2.2 - Adding filter and search




 Now

                                                 Finally
                      search by name




                                       filter by MIME type
Adding filter and search
                                                   WebDirectory/admin.py
 from WebDirectory.models import Entry
 from django.contrib import admin
     
   
   
   
   
   


 Class 
       Class EntryAdmin(admin.ModelAdmin):
     fieldsets = [
             ('File info', {'fields': ['name','webpage']}),
             ('Upload image', {'fields': ['image','mimeType']})]


     list_display = ('name', 'mimeType', 'webpage')


     list_filter = ['mimeType']


     search_fields = ['name']
 
   
   
 admin.site.register(Entry, MyAdmin)
Advanced Customization
More customization




•   We should be able to change the entire page layout

✓   Redefine HTML and CSS of the admin pages

➡   Redefine (extends) the predefined admin templates
Step 1 - Create an admin directory in the project


            tsansweb/
                __init__.py
                manage.py
                settings.py
                urls.py
                WebDirectory/
                admin/
                   templates/
                       admin/
Step 2 - Copy the admin templates

•    Find your Django installation path
    $ python
    >> import django                        my django_path
    >> django.__file__
    '/Library/Python/2.7/site-packages/django/__init__.pyc'



 •   Copy the templates index.html and base_site.html
     from django_path/contrib/admin/templates/admin/
     to project_path/tsansweb/admin/templates/
For example, change the title of the admin portal

                                   admin/templates/admin/base_site.html
 {% extends "admin/base.html" %}
 {% load i18n %}                          title in the header

 {% block title %}{{ title }}
 | {% trans 'My Custom Admin Portal' %}{% endblock %}


 {% block branding %}
 <h1 id="site-name">{% trans 'My Custom Admin Portal' %}</h1>
 {% endblock %}


 {% block nav-global %}{% endblock %}            title in the body

Weitere ähnliche Inhalte

Ähnlich wie Admin

Simple Contact Us Plugin Development
Simple Contact Us Plugin DevelopmentSimple Contact Us Plugin Development
Simple Contact Us Plugin Developmentwpnepal
 
Working With The Symfony Admin Generator
Working With The Symfony Admin GeneratorWorking With The Symfony Admin Generator
Working With The Symfony Admin GeneratorJohn Cleveley
 
Chandra Prakash Thapa: Make a WordPress Multisite in 20 mins
Chandra Prakash Thapa: Make a WordPress Multisite in 20 minsChandra Prakash Thapa: Make a WordPress Multisite in 20 mins
Chandra Prakash Thapa: Make a WordPress Multisite in 20 minswpnepal
 
IBM Connect 2014 - AD105: IBM iNotes and IBM SmartCloud Notes Web Customizati...
IBM Connect 2014 - AD105: IBM iNotes and IBM SmartCloud Notes Web Customizati...IBM Connect 2014 - AD105: IBM iNotes and IBM SmartCloud Notes Web Customizati...
IBM Connect 2014 - AD105: IBM iNotes and IBM SmartCloud Notes Web Customizati...IBM Connections Developers
 
ASP.NET User Controls - 20090828
ASP.NET User Controls - 20090828ASP.NET User Controls - 20090828
ASP.NET User Controls - 20090828Viral Patel
 
WordPress - Custom Page Settings + Salesforce API Integration
WordPress - Custom Page Settings + Salesforce API IntegrationWordPress - Custom Page Settings + Salesforce API Integration
WordPress - Custom Page Settings + Salesforce API IntegrationKhoi Nguyen
 
Worcamp2012 make a wordpress multisite in 20mins
Worcamp2012 make a wordpress multisite in 20minsWorcamp2012 make a wordpress multisite in 20mins
Worcamp2012 make a wordpress multisite in 20minsChandra Prakash Thapa
 
WordPress Developers Israel Meetup #1
WordPress Developers Israel Meetup #1WordPress Developers Israel Meetup #1
WordPress Developers Israel Meetup #1Yoav Farhi
 
Simple module Development in Joomla! 2.5
Simple module Development in Joomla! 2.5Simple module Development in Joomla! 2.5
Simple module Development in Joomla! 2.5Vishwash Gaur
 
Wordpress plugin creation_overview
Wordpress plugin creation_overviewWordpress plugin creation_overview
Wordpress plugin creation_overviewDaniel Kline
 
Joomla Beginner Template Presentation
Joomla Beginner Template PresentationJoomla Beginner Template Presentation
Joomla Beginner Template Presentationalledia
 
Intro to WordPress Plugin Development
Intro to WordPress Plugin DevelopmentIntro to WordPress Plugin Development
Intro to WordPress Plugin DevelopmentBrad Williams
 
Introduction to Plugin Programming, WordCamp Miami 2011
Introduction to Plugin Programming, WordCamp Miami 2011Introduction to Plugin Programming, WordCamp Miami 2011
Introduction to Plugin Programming, WordCamp Miami 2011David Carr
 

Ähnlich wie Admin (20)

Simple Contact Us Plugin Development
Simple Contact Us Plugin DevelopmentSimple Contact Us Plugin Development
Simple Contact Us Plugin Development
 
Django web framework
Django web frameworkDjango web framework
Django web framework
 
Mini Curso de Django
Mini Curso de DjangoMini Curso de Django
Mini Curso de Django
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to Django
 
Django
DjangoDjango
Django
 
Working With The Symfony Admin Generator
Working With The Symfony Admin GeneratorWorking With The Symfony Admin Generator
Working With The Symfony Admin Generator
 
Chandra Prakash Thapa: Make a WordPress Multisite in 20 mins
Chandra Prakash Thapa: Make a WordPress Multisite in 20 minsChandra Prakash Thapa: Make a WordPress Multisite in 20 mins
Chandra Prakash Thapa: Make a WordPress Multisite in 20 mins
 
IBM Connect 2014 - AD105: IBM iNotes and IBM SmartCloud Notes Web Customizati...
IBM Connect 2014 - AD105: IBM iNotes and IBM SmartCloud Notes Web Customizati...IBM Connect 2014 - AD105: IBM iNotes and IBM SmartCloud Notes Web Customizati...
IBM Connect 2014 - AD105: IBM iNotes and IBM SmartCloud Notes Web Customizati...
 
ASP.NET User Controls - 20090828
ASP.NET User Controls - 20090828ASP.NET User Controls - 20090828
ASP.NET User Controls - 20090828
 
WordPress - Custom Page Settings + Salesforce API Integration
WordPress - Custom Page Settings + Salesforce API IntegrationWordPress - Custom Page Settings + Salesforce API Integration
WordPress - Custom Page Settings + Salesforce API Integration
 
Worcamp2012 make a wordpress multisite in 20mins
Worcamp2012 make a wordpress multisite in 20minsWorcamp2012 make a wordpress multisite in 20mins
Worcamp2012 make a wordpress multisite in 20mins
 
WordPress Developers Israel Meetup #1
WordPress Developers Israel Meetup #1WordPress Developers Israel Meetup #1
WordPress Developers Israel Meetup #1
 
Simple module Development in Joomla! 2.5
Simple module Development in Joomla! 2.5Simple module Development in Joomla! 2.5
Simple module Development in Joomla! 2.5
 
Theme customization
Theme customizationTheme customization
Theme customization
 
Wordpress plugin creation_overview
Wordpress plugin creation_overviewWordpress plugin creation_overview
Wordpress plugin creation_overview
 
Joomla Beginner Template Presentation
Joomla Beginner Template PresentationJoomla Beginner Template Presentation
Joomla Beginner Template Presentation
 
Intro to WordPress Plugin Development
Intro to WordPress Plugin DevelopmentIntro to WordPress Plugin Development
Intro to WordPress Plugin Development
 
Introduction to Plugin Programming, WordCamp Miami 2011
Introduction to Plugin Programming, WordCamp Miami 2011Introduction to Plugin Programming, WordCamp Miami 2011
Introduction to Plugin Programming, WordCamp Miami 2011
 
Creating custom themes in AtoM
Creating custom themes in AtoMCreating custom themes in AtoM
Creating custom themes in AtoM
 
DJango
DJangoDJango
DJango
 

Kürzlich hochgeladen

Meet the new FSP 3000 M-Flex800™
Meet the new FSP 3000 M-Flex800™Meet the new FSP 3000 M-Flex800™
Meet the new FSP 3000 M-Flex800™Adtran
 
UiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation DevelopersUiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation DevelopersUiPathCommunity
 
Linked Data in Production: Moving Beyond Ontologies
Linked Data in Production: Moving Beyond OntologiesLinked Data in Production: Moving Beyond Ontologies
Linked Data in Production: Moving Beyond OntologiesDavid Newbury
 
UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8DianaGray10
 
9 Steps For Building Winning Founding Team
9 Steps For Building Winning Founding Team9 Steps For Building Winning Founding Team
9 Steps For Building Winning Founding TeamAdam Moalla
 
Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1DianaGray10
 
Empowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership BlueprintEmpowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership BlueprintMahmoud Rabie
 
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration WorkflowsIgniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration WorkflowsSafe Software
 
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPAAnypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPAshyamraj55
 
AI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just MinutesAI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just MinutesMd Hossain Ali
 
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...Will Schroeder
 
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...UbiTrack UK
 
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IES VE
 
OpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureOpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureEric D. Schabell
 
NIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 WorkshopNIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 WorkshopBachir Benyammi
 
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostKubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostMatt Ray
 
20230202 - Introduction to tis-py
20230202 - Introduction to tis-py20230202 - Introduction to tis-py
20230202 - Introduction to tis-pyJamie (Taka) Wang
 
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfUiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfDianaGray10
 

Kürzlich hochgeladen (20)

Meet the new FSP 3000 M-Flex800™
Meet the new FSP 3000 M-Flex800™Meet the new FSP 3000 M-Flex800™
Meet the new FSP 3000 M-Flex800™
 
UiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation DevelopersUiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation Developers
 
Linked Data in Production: Moving Beyond Ontologies
Linked Data in Production: Moving Beyond OntologiesLinked Data in Production: Moving Beyond Ontologies
Linked Data in Production: Moving Beyond Ontologies
 
UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8
 
9 Steps For Building Winning Founding Team
9 Steps For Building Winning Founding Team9 Steps For Building Winning Founding Team
9 Steps For Building Winning Founding Team
 
Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1
 
Empowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership BlueprintEmpowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership Blueprint
 
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration WorkflowsIgniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
 
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPAAnypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPA
 
201610817 - edge part1
201610817 - edge part1201610817 - edge part1
201610817 - edge part1
 
AI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just MinutesAI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just Minutes
 
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
 
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
 
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
 
OpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureOpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability Adventure
 
NIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 WorkshopNIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 Workshop
 
20230104 - machine vision
20230104 - machine vision20230104 - machine vision
20230104 - machine vision
 
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostKubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
 
20230202 - Introduction to tis-py
20230202 - Introduction to tis-py20230202 - Introduction to tis-py
20230202 - Introduction to tis-py
 
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfUiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
 

Admin

  • 2. A blog web application • We need to have an interface to • post, delete and modify articles • moderate comments • manage authorized writers and viewers ➡ We need an administration interface
  • 3. Why having an administration interface • Inspecting data see what the database contains • Managing acquired data insert, modify and delete database records • Managing users define who can access your application ✓ All of these should be accessible for non technical users
  • 4. How to build such an administrator interface? ➡ We could build the administrator interface from scratch ๏ It's painfully, boring and repetitive to build it ✓ With Django “batteries are included”
  • 5. Django provides ✓ An optional, pluggable and customizable admin interface ... ... and it looks really good!
  • 6. Activate the admin interface for your Django project
  • 7. Step 1 - Modify the project settings ... setting.py INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.messages', 'django.contrib.staticfiles', 'WebDirectory', # Uncomment the next line to enable the admin: 'django.contrib.admin', # Uncomment the next line to enable admin documentation: # 'django.contrib.admindocs', ) ...
  • 8. Step 2 - Re-synchronize the database $ python manage.py syncdb
  • 9. Step 3 - Modify the project URL Dispatcher urls.py from django.conf.urls.defaults import patterns, include, url urlpatterns = patterns('', (r'^webdirectory/', include('WebDirectory.urls'))) from django.contrib import admin admin.autodiscover() urlpatterns += patterns('',(r'^admin/', include(admin.site.urls)))
  • 10. The admin interface is ready!
  • 11. The admin interface is ready! URL of the admin site
  • 12. The admin interface is ready! URL of the admin site So far, you can login as the superuser created during the first database sync
  • 13. Activate the admin interface for the WebDirectory app
  • 14. Step 1 - Create the admin.py file in WebDirectory WebDirectory/ __init__.py models.py test.py views.py urls.py admin.py templates/ static/
  • 15. Step 2 - Modify admin.py WebDirectory/admin.py from WebDirectory.models import Entry from django.contrib import admin admin.site.register(Entry)
  • 16. Step 2 - Modify admin.py WebDirectory/admin.py from WebDirectory.models import Entry from django.contrib import admin admin.site.register(Entry) makes the Entry data model available on the admin interface
  • 20. From WebDirectory admin you can get the list of records
  • 21. From WebDirectory admin you can add records get the list of records
  • 22. From WebDirectory admin you can add records get the list of records
  • 23. From WebDirectory admin you can add records get the list of records modify records
  • 24. From WebDirectory admin you can add records get the list of records modify records delete records
  • 25. Creating a dedicated administrator for WebDirectory
  • 26. The superuser administrator has all powers • Create, modify and delete users • Insert, modify, delete records from every application
  • 27. How to be more restrictive? ✓ We want to create an administrator for the WebDirectory application only • A dedicated user admin named John Doe - login: jdoe • With the administrative privileges to create, modify and delete records in WebDirectory only
  • 28. Create the John Doe admin user
  • 32. login and password user’s information staff = admin power
  • 33. login and password user’s information staff = admin power give all administrative permissions for WebDirectory
  • 35. What the administrator can do After logging in as jdoe ...
  • 36. What the administrator can do After logging in as jdoe ... ... John Doe can administrate WebDirectory only
  • 37. Customize the admin interface
  • 38. How to customize the admin interface? ✓ By editing the admin.py • The class ModelAdmin is the representation of the models in the admin interface • Changing the admin options 1. create a new model admin object class EntryAdmin(admin.ModelAdmin): ... 2. register this new admin object admin.site.register()
  • 39. Task 1 - Customizing the interface for editing a record Default
  • 40. Task 1 - Customizing the interface for editing a record Default Finally fields grouped in fieldsets
  • 41. Task 1.1 - Modify the field order when editing a record Default
  • 42. Task 1.1 - Modify the field order when editing a record Default After fields reordered
  • 43. Task 1.1 - Editing admin.py WebDirectory/admin.py from WebDirectory.models import Entry from django.contrib import admin Class EntryAdmin(admin.ModelAdmin): fields = ['name', 'image', 'mimeType', 'webpage'] admin.site.register(Entry,EntryAdmin)
  • 44. Task 1.2 - Splitting fields into field sets Now
  • 45. Task 1.2 - Splitting fields into field sets Now Finally fields grouped in fieldsets
  • 46. Task 1.2 - Editing admin.py WebDirectory/admin.py from WebDirectory.models import Entry from django.contrib import admin Class Class EntryAdmin(admin.ModelAdmin): fieldsets = [ ('File info', {'fields': ['name','webpage']}), ('Upload image', {'fields': ['image','mimeType']})] admin.site.register(Entry, MyAdmin)
  • 47. Task 2 - Customizing the interface for listing all records Default
  • 48. Task 2 - Customizing the interface for listing all records Default Finally Multiple attributes displayed
  • 49. Task 2 - Customizing the interface for listing all records Default Finally search by name Multiple attributes displayed
  • 50. Task 2 - Customizing the interface for listing all records Default Finally search by name Multiple attributes displayed filter by MIME type
  • 51. Task 2.1 - Changing the record list output Default
  • 52. Task 2.1 - Changing the record list output Default After Multiple attributes displayed
  • 53. Task 2.1 - Editing admin.py WebDirectory/admin.py from WebDirectory.models import Entry from django.contrib import admin Class Class EntryAdmin(admin.ModelAdmin): fieldsets = [ ('File info', {'fields': ['name','webpage']}), ('Upload image', {'fields': ['image','mimeType']})] list_display = ('name', 'mimeType', 'webpage') admin.site.register(Entry, MyAdmin)
  • 54. Task 2.2 - Adding filter and search Now
  • 55. Task 2.2 - Adding filter and search Now Finally search by name filter by MIME type
  • 56. Adding filter and search WebDirectory/admin.py from WebDirectory.models import Entry from django.contrib import admin Class Class EntryAdmin(admin.ModelAdmin): fieldsets = [ ('File info', {'fields': ['name','webpage']}), ('Upload image', {'fields': ['image','mimeType']})] list_display = ('name', 'mimeType', 'webpage') list_filter = ['mimeType'] search_fields = ['name'] admin.site.register(Entry, MyAdmin)
  • 58. More customization • We should be able to change the entire page layout ✓ Redefine HTML and CSS of the admin pages ➡ Redefine (extends) the predefined admin templates
  • 59. Step 1 - Create an admin directory in the project tsansweb/ __init__.py manage.py settings.py urls.py WebDirectory/ admin/ templates/ admin/
  • 60. Step 2 - Copy the admin templates • Find your Django installation path $ python >> import django my django_path >> django.__file__ '/Library/Python/2.7/site-packages/django/__init__.pyc' • Copy the templates index.html and base_site.html from django_path/contrib/admin/templates/admin/ to project_path/tsansweb/admin/templates/
  • 61. For example, change the title of the admin portal admin/templates/admin/base_site.html {% extends "admin/base.html" %} {% load i18n %} title in the header {% block title %}{{ title }} | {% trans 'My Custom Admin Portal' %}{% endblock %} {% block branding %} <h1 id="site-name">{% trans 'My Custom Admin Portal' %}</h1> {% endblock %} {% block nav-global %}{% endblock %} title in the body

Hinweis der Redaktion

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n
  42. \n
  43. \n
  44. \n
  45. \n
  46. \n
  47. \n
  48. \n
  49. \n
  50. \n
  51. \n
  52. \n
  53. \n
  54. \n
  55. \n
  56. \n
  57. \n
  58. \n
  59. \n
  60. \n
  61. \n
  62. \n
  63. \n
  64. \n