Skip to content

Instantly share code, notes, and snippets.

@benzkji
Last active March 3, 2017 13:08
Show Gist options
  • Save benzkji/0d6d96334db1051753db to your computer and use it in GitHub Desktop.
Save benzkji/0d6d96334db1051753db to your computer and use it in GitHub Desktop.
django-cms page form customized
from django.contrib import admin
from django import forms
from django.utils.translation import ugettext_lazy as _
from cms.models import Page
from cms.admin.forms import PageForm
from cms.admin.pageadmin import PageAdmin
class CustomPageForm(PageForm):
page_title = forms.CharField(label=_("Title Tag"), widget=forms.TextInput(),
help_text=_('Overwrites what is displayed at the top of your '
'browser or in bookmarks'),
required=False)
def __init__(self, *args, **kwargs):
super(CustomPageForm, self).__init__(*args, **kwargs)
self.fields['menu_title'].widget = forms.HiddenInput()
class CustomPageAdmin(PageAdmin):
def get_form_class(self, request, obj=None, **kwargs):
form_class = super(CustomPageAdmin, self).get_form_class(request, obj, **kwargs)
if form_class == self.form:
form_class = CustomPageForm
return form_class
admin.site.unregister(Page)
admin.site.register(Page, CustomPageAdmin)
@benzkji
Copy link
Author

benzkji commented Jun 26, 2015

note to self: in INSTALLED_APPS, cms must be before your app containing this admin.py. this means you can nomore override cms menu templates - but specify them explicitly in the menu tags.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment