Created
July 21, 2018 19:11
-
-
Save KalobTaulien/fd647fabfb5210203c697dc5694d2633 to your computer and use it in GitHub Desktop.
Wagtail 2: Changing the title and help text of a default Wagtail Page field
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 wagtail.core.models import Page | |
class YourPage(Page): | |
"""Your Wagtail Page Type.""" | |
template = "templates/your_page.html" | |
# Other Page fields | |
YourPage._meta.get_field('title').verbose_name = 'New Default Title' | |
YourPage._meta.get_field('title').help_text = 'New Help Text For Default Title' |
@gasman what do you suggest?
I can see the same approach here:
https://learnwagtail.com/tutorials/customizing-default-property-values/
@gasman I struggle to find an alternative to the solution proposed by Kalob. Any hint to do it another way? Thanks in advance
Setting up a custom form class as per https://docs.wagtail.org/en/stable/advanced_topics/customisation/page_editing_interface.html#customising-generated-forms and overriding the help_text / label on the form field there (rather than the model field) is probably the way to go.
@gasman many thanks for your quick reply!
Thanks @gasman for your input. Here is my solution to override default title information (maybe it will help others). No more issues when migrating in production 👍
class CoursePageForm(WagtailAdminPageForm):
title = forms.CharField(max_length='255',
label="Custom label",
help_text="Custom help text",
widget=forms.TextInput(attrs={'placeholder': "Custom placeholder"})
)
class CoursePage(Page):
image = models.ForeignKey(
'wagtailimages.Image',
blank=True,
null=True,
on_delete=models.SET_NULL,
related_name="+",
verbose_name="bla bla"
)
description = models.TextField(blank=True, verbose_name="Bla bla bla")
content_panels = Page.content_panels + [
MultiFieldPanel(
[
FieldPanel('image'),
FieldPanel('description'),
], heading="Cours"
),
]
base_form_class = CoursePageForm
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I wouldn't recommend doing this - Django will see this as a change to the base Page model and create a migration for it inside the wagtail.core app when you next run
makemigrations
, and that migration will disappear when you subsequently upgrade Wagtail.