• Save
Admin
Upcoming SlideShare
Loading in...5
×
 

Admin

on

  • 784 views

 

Statistics

Views

Total Views
784
Views on SlideShare
784
Embed Views
0

Actions

Likes
0
Downloads
0
Comments
0

0 Embeds 0

No embeds

Accessibility

Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n

Admin Admin Presentation Transcript

  • 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๏ Its 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.pyfrom django.conf.urls.defaults import patterns, include, urlurlpatterns = patterns(, (r^webdirectory/, include(WebDirectory.urls)))from django.contrib import adminadmin.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
  • 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 recordsdelete 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
  • login and password
  • login and passworduser’s information
  • login and password user’s informationstaff = admin power
  • login and password user’s informationstaff = 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 recordDefault
  • Task 1 - Customizing the interface for editing a recordDefault Finally fields grouped in fieldsets
  • Task 1.1 - Modify the field order when editing a recordDefault
  • Task 1.1 - Modify the field order when editing a recordDefault 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 setsNow
  • Task 1.2 - Splitting fields into field setsNow 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 recordsDefault
  • Task 2 - Customizing the interface for listing all recordsDefault Finally Multiple attributes displayed
  • Task 2 - Customizing the interface for listing all recordsDefault Finally search by name Multiple attributes displayed
  • Task 2 - Customizing the interface for listing all recordsDefault Finally search by name Multiple attributes displayed filter by MIME type
  • Task 2.1 - Changing the record list outputDefault
  • Task 2.1 - Changing the record list outputDefault 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