Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ###
- # Project: CMDO Clan Website
- #
- # Copyright (C) 2012 lengend. All rights reserved.
- ###
- ### Module: Site.Administration
- ### Imports
- from models import Page
- from django.utils.translation import ugettext as _
- from django.contrib import admin
- from django.contrib.admin.widgets import AdminTextInputWidget
- from django import forms
- ### Page administration form
- class PageForm(forms.ModelForm):
- def __init__(self, *args, **kwargs):
- super ( PageForm, self ).__init__ ( *args, **kwargs )
- if ( self.instance and self.instance.pk ):
- self.fields [ 'key' ].widget = AdminTextInputWidget ( attrs = { 'readonly': 'readonly' } )
- def clean_key(self):
- if ( self.instance and self.instance.pk ):
- if ( self.instance.key != self.cleaned_data [ 'key' ] ):
- raise forms.ValidationError ( _ ( 'This field is read only.' ) )
- return self.instance.key
- else: return self.cleaned_data [ 'key' ]
- class Meta:
- model = Page
- ### Page administration model
- class PageAdmin(admin.ModelAdmin):
- ### Form configuration
- form = PageForm
- ### Field configuration
- list_display = ( 'key', )
- search_fields = ( 'key', 'body', )
- ### Media configuration
- class Media:
- js = ( 'administration/js/tiny_mce/tiny_mce.js', 'administration/js/tiny_mce/tiny_mce_setup.js', )
- ### Registrations
- def autodiscover():
- admin.site.register ( Page, PageAdmin )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement