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. Template tag - list punctuation for a list of items by shapiromatron 9 months, 4 weeks ago
  2. JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 10 months ago
  3. Serializer factory with Django Rest Framework by julio 1 year, 4 months ago
  4. Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 5 months ago
  5. Help text hyperlinks by sa2812 1 year, 6 months ago

Comments

Please login first before commenting.