SlideShare a Scribd company logo
The Django Admin Interface
Activate Django Admin SiteAdd 'django.contrib.admin' to your INSTALLED_APPS setting.Add - django.contrib.auth, django.contrib.contenttypes and django.contrib.messages. Add django.contrib.messages.context_processors.messagesto TEMPLATE_CONTEXT_PROCESSORS and django.contrib.messages.middleware.MessageMiddlewaretoMIDDLEWARE_CLASSES. Determine which of your application’s models should be editable in the admin interface.For each of those models, optionally create a ModelAdmin class that encapsulates the customized admin functionality and options for that particular model.Hook the AdminSite instance into your URLconf.
Exact Look
ModelAdminThe ModelAdmin class is the representation of a model in the admin interface. These are stored in a file named admin.py in your application. Eg :from django.contrib import adminfrom myproject.myapp.models import Authorclass AuthorAdmin(admin.ModelAdmin):	//    Attributesadmin.site.register(Author, AuthorAdmin)
Behavior ModelAdmin.list_displayfields are displayed on the change list page of the adminModelAdmin.search_fieldsSet search_fields to enable a search box on the admin change list pageModelAdmin.orderingSet ordering to specify how lists of objects should be ordered in the Django admin viewsModelAdmin.list_display_linksSet list_display_links to control which fields in list_display should be linked to the "change" page for an objectModelAdmin.fields if you want to only show a subset of the available fields in the formModelAdmin.exclude list of field names to exclude from the form
BehaviorModelAdmin.fieldsets :Set fieldsets to control the layout of admin "add" and "change" pagefieldsets is a list of two-tuples, in which each two-tuple represents a <fieldset> on the admin form page. (A <fieldset> is a "section" of the form.)The two-tuples are in the format (name, field_options), where name is a string representing the title of the fieldset and field_options is a dictionary of information about the fieldset, including a list of fields to be displayed in it.ModelAdmin.paginator :The paginator class to be used for pagination
BehaviorEgclass FlatPageAdmin(admin.ModelAdmin):fieldsets = (        (None, {            'fields': ('url', 'title', 'content', 'sites')        }),        ('Advanced options', {            'classes': ('collapse',),            'fields': ('enable_comments', 'registration_required', 'template_name')        }),    )To display multiple fields on the same line:{'fields': (('first_name', 'last_name'), 'address', 'city', 'state'),}
admin actionsneed to make the same change to many objectsEgSuppose you want to make all the cache’s status as Truedef make_published(modeladmin, request, queryset):queryset.update(status=True)make_published.short_description = "Mark selected stories as published“The current ModelAdminAn HttpRequest representing the current request,A QuerySet containing the set of objects selected by the user.
admin actionsdef make_available(modeladmin, request, queryset):queryset.update(status=True)make_available.short_description = "Mark selected cache’s as available“# Just  add the actions in the admin modelclass ArticleAdmin(admin.ModelAdmin):list_display = ['title', 'status']         ordering = ['title']         actions = [make_available]Disable The Actions:admin.site.disable_action('delete_selected‘)
optionsA list of actions to make available on the change list page. ModelAdmin.actions_on_topModelAdmin.actions_on_bottomControls where on the page the actions bar appears. By default, the admin changelist displays actions at the top of the page (actions_on_top = True; actions_on_bottom = False).ModelAdmin.actions_selection_counterControls whether a selection counter is display next to the action dropdown. By default, the admin changelist will display it (actions_selection_counter = True).
Hooking AdminSite into URLconf# urls.pyfrom django.conf.urls.defaults import *from django.contrib import adminadmin.autodiscover()urlpatterns = patterns('',    (r'^admin/', include(admin.site.urls)),)
Hooking AdminSite into URLconf# urls.pyfrom django.conf.urls.defaults import *from myproject.admin import admin_siteurlpatterns = patterns('',    (r'^myadmin/', include(admin_site.urls)),)
Multiple admin sites in the same URLconf# urls.pyfrom django.conf.urls.defaults import *from myproject.admin import basic_site, advanced_siteurlpatterns = patterns('',    (r'^basic-admin/', include(basic_site.urls)),    (r'^advanced-admin/', include(advanced_site.urls)),)
AssignmentsStudy the following  componentsModelAdmin.filter_horizontalModelAdmin.filter_verticalModelAdmin.formModelAdmin.formfield_overrideslist_filterlist_select_relatedprepopulated_fieldsModelAdmin.radio_fieldsModelAdmin.save_asModelAdmin.save_on_topclass InlineModelAdminclass TabularInlineclass StackedInlineModelAdmin.raw_id_fields
Thanks

More Related Content

KEY
Django Admin: Widgetry & Witchery
PDF
날로 먹는 Django admin 활용
PDF
Django Templates
PDF
Django Vs Rails
PPTX
HOW TO CREATE A MODULE IN ODOO
PPTX
Modules and injector
PDF
Resource and view
PDF
AngularJS vs. Ember.js vs. Backbone.js
Django Admin: Widgetry & Witchery
날로 먹는 Django admin 활용
Django Templates
Django Vs Rails
HOW TO CREATE A MODULE IN ODOO
Modules and injector
Resource and view
AngularJS vs. Ember.js vs. Backbone.js

What's hot (20)

PDF
Dependency Management with RequireJS
PDF
Django design-patterns
PDF
Forms, Getting Your Money's Worth
PPTX
Editing the Visual Editor (WordPress)
PPTX
Angular 2.0 forms
PPTX
Odoo (Build module, Security, ORM)
PPTX
Magento 2.0: Prepare yourself for a new way of module development
PDF
Two scoops of django 1.6 - Ch7, Ch8
PDF
JavaScript for Flex Devs
PPTX
Django: Advanced Models
PPTX
Angular 2 Architecture (Bucharest 26/10/2016)
PDF
WordPress Capabilities Magic
PDF
Technical training sample
PDF
Javascript MVC & Backbone Tips & Tricks
PPTX
Performance Optimization In Angular 2
PDF
Django class based views for beginners
PPTX
20150515ken
PDF
Working with Javascript in Rails
PDF
Make your App Frontend Compatible
PPTX
AngularJS Internal
Dependency Management with RequireJS
Django design-patterns
Forms, Getting Your Money's Worth
Editing the Visual Editor (WordPress)
Angular 2.0 forms
Odoo (Build module, Security, ORM)
Magento 2.0: Prepare yourself for a new way of module development
Two scoops of django 1.6 - Ch7, Ch8
JavaScript for Flex Devs
Django: Advanced Models
Angular 2 Architecture (Bucharest 26/10/2016)
WordPress Capabilities Magic
Technical training sample
Javascript MVC & Backbone Tips & Tricks
Performance Optimization In Angular 2
Django class based views for beginners
20150515ken
Working with Javascript in Rails
Make your App Frontend Compatible
AngularJS Internal
Ad

Viewers also liked (20)

PDF
Magic Methods (Python meetup)
PDF
Django Admin (Python meeutp)
PPTX
Are you and your computer guy praying 3
PDF
Facebook Platform - Hack Thursday CW 40
PDF
EarthLink Top 5 Questions Asked of EarthLInk Network Engineers 2016
PDF
Amir33202057 2013 03-17-19-06-07
PPTX
Via3 Project In Control
PDF
Setmore zendesk integration - quick walkthrough
PDF
HubSpot Activation on BlueCamroo
PDF
Serveau software f
PDF
Appraisly November 2013
PPTX
Enterprise Risk Management
PDF
Inception Product Feature Webinar: Workflow, Versioning & Restore
PPT
Product families
PPTX
Design is...
PPT
Trance'former présentation eng
PPTX
SFPUC and DataSplice Mobile for Maximo
PPTX
OnSync Manual Account Holders and Moderators
PPTX
Government encourages education loan
PPTX
TechZarInfo web design and development
Magic Methods (Python meetup)
Django Admin (Python meeutp)
Are you and your computer guy praying 3
Facebook Platform - Hack Thursday CW 40
EarthLink Top 5 Questions Asked of EarthLInk Network Engineers 2016
Amir33202057 2013 03-17-19-06-07
Via3 Project In Control
Setmore zendesk integration - quick walkthrough
HubSpot Activation on BlueCamroo
Serveau software f
Appraisly November 2013
Enterprise Risk Management
Inception Product Feature Webinar: Workflow, Versioning & Restore
Product families
Design is...
Trance'former présentation eng
SFPUC and DataSplice Mobile for Maximo
OnSync Manual Account Holders and Moderators
Government encourages education loan
TechZarInfo web design and development
Ad

Similar to DJango admin interface (20)

KEY
Admin
PDF
PDF
Chapter 6 the django admin site
PDF
Customizing the Django Admin
PDF
What’S New In Newforms Admin
ODP
Django for Beginners
PDF
Django admin
PDF
那些年,我用 Django Admin 接的案子
PDF
Python Expense Tracker Project with Source Code.pdf
PPTX
The Django Web Application Framework 2
PPTX
The Django Web Application Framework 2
PPTX
The Django Web Application Framework 2
PPTX
The Django Web Application Framework 2
PDF
Basic Crud In Django
PDF
Introduction to django
PDF
Django Heresies
PPTX
E-Bazaar
PPTX
Django web framework
PPT
DJango
PPTX
Django Portfolio Website Workshop (1).pptx
Admin
Chapter 6 the django admin site
Customizing the Django Admin
What’S New In Newforms Admin
Django for Beginners
Django admin
那些年,我用 Django Admin 接的案子
Python Expense Tracker Project with Source Code.pdf
The Django Web Application Framework 2
The Django Web Application Framework 2
The Django Web Application Framework 2
The Django Web Application Framework 2
Basic Crud In Django
Introduction to django
Django Heresies
E-Bazaar
Django web framework
DJango
Django Portfolio Website Workshop (1).pptx

Recently uploaded (20)

PPTX
Institutional Correction lecture only . . .
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
O7-L3 Supply Chain Operations - ICLT Program
PPTX
GDM (1) (1).pptx small presentation for students
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
RMMM.pdf make it easy to upload and study
PPTX
Lesson notes of climatology university.
PDF
Computing-Curriculum for Schools in Ghana
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
Complications of Minimal Access Surgery at WLH
PPTX
Cell Structure & Organelles in detailed.
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
Pharma ospi slides which help in ospi learning
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Institutional Correction lecture only . . .
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
O7-L3 Supply Chain Operations - ICLT Program
GDM (1) (1).pptx small presentation for students
O5-L3 Freight Transport Ops (International) V1.pdf
RMMM.pdf make it easy to upload and study
Lesson notes of climatology university.
Computing-Curriculum for Schools in Ghana
FourierSeries-QuestionsWithAnswers(Part-A).pdf
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
Supply Chain Operations Speaking Notes -ICLT Program
Complications of Minimal Access Surgery at WLH
Cell Structure & Organelles in detailed.
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
2.FourierTransform-ShortQuestionswithAnswers.pdf
Module 4: Burden of Disease Tutorial Slides S2 2025
Anesthesia in Laparoscopic Surgery in India
Pharma ospi slides which help in ospi learning
102 student loan defaulters named and shamed – Is someone you know on the list?
Chapter 2 Heredity, Prenatal Development, and Birth.pdf

DJango admin interface

  • 1. The Django Admin Interface
  • 2. Activate Django Admin SiteAdd 'django.contrib.admin' to your INSTALLED_APPS setting.Add - django.contrib.auth, django.contrib.contenttypes and django.contrib.messages. Add django.contrib.messages.context_processors.messagesto TEMPLATE_CONTEXT_PROCESSORS and django.contrib.messages.middleware.MessageMiddlewaretoMIDDLEWARE_CLASSES. Determine which of your application’s models should be editable in the admin interface.For each of those models, optionally create a ModelAdmin class that encapsulates the customized admin functionality and options for that particular model.Hook the AdminSite instance into your URLconf.
  • 4. ModelAdminThe ModelAdmin class is the representation of a model in the admin interface. These are stored in a file named admin.py in your application. Eg :from django.contrib import adminfrom myproject.myapp.models import Authorclass AuthorAdmin(admin.ModelAdmin): // Attributesadmin.site.register(Author, AuthorAdmin)
  • 5. Behavior ModelAdmin.list_displayfields are displayed on the change list page of the adminModelAdmin.search_fieldsSet search_fields to enable a search box on the admin change list pageModelAdmin.orderingSet ordering to specify how lists of objects should be ordered in the Django admin viewsModelAdmin.list_display_linksSet list_display_links to control which fields in list_display should be linked to the "change" page for an objectModelAdmin.fields if you want to only show a subset of the available fields in the formModelAdmin.exclude list of field names to exclude from the form
  • 6. BehaviorModelAdmin.fieldsets :Set fieldsets to control the layout of admin "add" and "change" pagefieldsets is a list of two-tuples, in which each two-tuple represents a <fieldset> on the admin form page. (A <fieldset> is a "section" of the form.)The two-tuples are in the format (name, field_options), where name is a string representing the title of the fieldset and field_options is a dictionary of information about the fieldset, including a list of fields to be displayed in it.ModelAdmin.paginator :The paginator class to be used for pagination
  • 7. BehaviorEgclass FlatPageAdmin(admin.ModelAdmin):fieldsets = ( (None, { 'fields': ('url', 'title', 'content', 'sites') }), ('Advanced options', { 'classes': ('collapse',), 'fields': ('enable_comments', 'registration_required', 'template_name') }), )To display multiple fields on the same line:{'fields': (('first_name', 'last_name'), 'address', 'city', 'state'),}
  • 8. admin actionsneed to make the same change to many objectsEgSuppose you want to make all the cache’s status as Truedef make_published(modeladmin, request, queryset):queryset.update(status=True)make_published.short_description = "Mark selected stories as published“The current ModelAdminAn HttpRequest representing the current request,A QuerySet containing the set of objects selected by the user.
  • 9. admin actionsdef make_available(modeladmin, request, queryset):queryset.update(status=True)make_available.short_description = "Mark selected cache’s as available“# Just add the actions in the admin modelclass ArticleAdmin(admin.ModelAdmin):list_display = ['title', 'status'] ordering = ['title'] actions = [make_available]Disable The Actions:admin.site.disable_action('delete_selected‘)
  • 10. optionsA list of actions to make available on the change list page. ModelAdmin.actions_on_topModelAdmin.actions_on_bottomControls where on the page the actions bar appears. By default, the admin changelist displays actions at the top of the page (actions_on_top = True; actions_on_bottom = False).ModelAdmin.actions_selection_counterControls whether a selection counter is display next to the action dropdown. By default, the admin changelist will display it (actions_selection_counter = True).
  • 11. Hooking AdminSite into URLconf# urls.pyfrom django.conf.urls.defaults import *from django.contrib import adminadmin.autodiscover()urlpatterns = patterns('', (r'^admin/', include(admin.site.urls)),)
  • 12. Hooking AdminSite into URLconf# urls.pyfrom django.conf.urls.defaults import *from myproject.admin import admin_siteurlpatterns = patterns('', (r'^myadmin/', include(admin_site.urls)),)
  • 13. Multiple admin sites in the same URLconf# urls.pyfrom django.conf.urls.defaults import *from myproject.admin import basic_site, advanced_siteurlpatterns = patterns('', (r'^basic-admin/', include(basic_site.urls)), (r'^advanced-admin/', include(advanced_site.urls)),)
  • 14. AssignmentsStudy the following componentsModelAdmin.filter_horizontalModelAdmin.filter_verticalModelAdmin.formModelAdmin.formfield_overrideslist_filterlist_select_relatedprepopulated_fieldsModelAdmin.radio_fieldsModelAdmin.save_asModelAdmin.save_on_topclass InlineModelAdminclass TabularInlineclass StackedInlineModelAdmin.raw_id_fields