Login

Overriding Third-party Admin

Author:
mattdw
Posted:
September 7, 2008
Language:
Python
Version:
1.0
Tags:
admin newforms-admin custom contrib.admin override rich-text
Score:
6 (after 6 ratings)

With the advent of newforms-admin it's now possible to override admin interfaces without having to change any code in third-party modules. This example shows how to enable a rich-text editor for django.contrib.flatpages without touching Django's code at all. (Actual embedding of the editor via Javascript left as an exercise for the reader – plenty of examples of that elsewhere.)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#
# myproject/admin.py
#

from django.contrib import admin
from django.contrib.flatpages.models import FlatPage

# Override flatpage admin
class FlatPageAdmin(admin.ModelAdmin):
    class Media:
        js = ('/media/j/jquery.js', 
              '/media/j/admin_enhancements.js')
        css = {'screen': ('/media/c/admin.css',)}
    
admin.site.unregister(FlatPage)
admin.site.register(FlatPage, FlatPageAdmin)


#
# myproject/urls.py
#

from django.contrib import admin
admin.autodiscover()
# import has to come after autodiscover, because we can't 
# unregister FlatPage until it's already been registered.
import myproject.admin

More like this

  1. YUI editor for flatpages inside admin interface by nnrcschmdt 7 years, 3 months ago
  2. FCKWidget for NewForms by Digitalxero 7 years, 5 months ago
  3. Confirm alert if the user navigates away without saving changes by mrazzari 5 years, 11 months ago
  4. FCKEditor replace all vLargeTextField in admin by aronchi 6 years, 8 months ago
  5. RadioSelectWithHelpText by moxypark 4 years, 10 months ago

Comments

Please login first before commenting.