Login

Overriding Third-party Admin

Author:
mattdw
Posted:
September 7, 2008
Language:
Python
Version:
1.0
Score:
7 (after 7 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. Django Settings Assignment Expressions aka Walrus Operator example by webology 3 weeks, 2 days ago
  2. codigo alto nivel by MrRocklion 2 months, 2 weeks ago
  3. Load template from specific app by Krzysiek555 3 months, 1 week ago
  4. PostgreSQL JSON subqueries by dolamroth 3 months, 1 week ago
  5. "Magic Link" Management Command by webology 8 months, 2 weeks ago

Comments

Please login first before commenting.