Last active
March 3, 2017 13:08
-
-
Save benzkji/0d6d96334db1051753db to your computer and use it in GitHub Desktop.
django-cms page form customized
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.