Skip to content

Instantly share code, notes, and snippets.

@KalobTaulien
Created July 21, 2018 19:11
Show Gist options
  • Save KalobTaulien/fd647fabfb5210203c697dc5694d2633 to your computer and use it in GitHub Desktop.
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
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
Copy link

gasman commented Oct 28, 2020

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.

@dest81
Copy link

dest81 commented Dec 10, 2020

@gasman what do you suggest?

@dest81
Copy link

dest81 commented Dec 10, 2020

@Araoo
Copy link

Araoo commented Jan 30, 2023

@gasman I struggle to find an alternative to the solution proposed by Kalob. Any hint to do it another way? Thanks in advance

@gasman
Copy link

gasman commented Jan 30, 2023

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.

@Araoo
Copy link

Araoo commented Jan 30, 2023

@gasman many thanks for your quick reply!

@Araoo
Copy link

Araoo commented Feb 1, 2023

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