Security News
Opengrep Emerges as Open Source Alternative Amid Semgrep Licensing Controversy
Opengrep forks Semgrep to preserve open source SAST in response to controversial licensing changes.
The Wagtail Form Builder functionalities available for your models/snippets.
The Wagtail Form Builder functionalities available for your models/snippets.
Install the package
pip install wagtail-model-forms
Add wagtail_model_forms
to your INSTALLED_APPS
INSTALLED_APPS = [
...
"wagtail_model_forms",
]
Create your models
from django.utils.functional import cached_property
from modelcluster.fields import ParentalKey
from wagtail.core.models import Page
from wagtail.snippets.models import register_snippet
from wagtail_model_forms.mixins import FormSnippetMixin
from wagtail_model_forms.models import AbstractForm, AbstractUploadedFile, AbstractFormSubmission
class FormSubmission(AbstractFormSubmission):
form = models.ForeignKey(
"Form",
on_delete=models.CASCADE,
related_name="+",
verbose_name=_("Form"),
)
class UploadedFile(AbstractUploadedFile):
pass
@register_snippet
class Form(AbstractForm):
@cached_property
def edit_url(self):
# return your url here, commonly your own modeladmin configuration
url_helper = FormModelAdmin().url_helper
return url_helper.get_action_url("edit", self.id)
class MyPage(FormSnippetMixin, Page):
pass
In order to let the page now that there is a form on it (handle post methods, caching etc.) we need to make sure the method page_has_form
returns True
. To make your life easier you can set the property streamfields
with the names of the StreamField which can have the form added. Also make sure the name of the block is matched, commonly called form
in your list of blocks. In some cases you might want to override this method and implement your own bespoke logic here.
from wagtail_model_forms.blocks import FormBlock
class MyPage(FormSnippetMixin, Page):
block_type = "form" # has by default already the value form
streamfields = ["content"] # the name of your streamfields
content = StreamField([
# your other blocks
("form", FormBlock()),
])
More advanced with your bespoke implementation
from django.utils.functional import cached_property
class MyPage(FormSnippetMixin, Page):
@cached_property
def page_has_form(self):
# your bespoke import in order to determine a form is on the page
It's not mandatory to use the register_snippet
functionality. You can e.g. use wagtailmodelchooser
for it or any other bespoke implementation in order to put the form on your page.
Default True
Must be of the form app_label.model_name
Must be of the form app_label.model_name
Must be of the form app_label.model_name
Default True
Default False
wagtail_model_forms/form.html
{% if not request.form_success is self.form.id %}
<form action="" method="POST" novalidate>
{% csrf_token %}
<input type="hidden" name="form_id" value="{{ self.form.id }}">
{{ form.as_ul }}
<button type="submit">Submit</button>
</form>
{% else %}
<p>Form success</p>
{% endif %}
Make sure you have added the FormSnippetMixin
and implemented the page_has_form
method correctly.
Make sure you render your blocks in your templates with include_block
, see https://docs.wagtail.org/en/stable/topics/streamfield.html.
FAQs
The Wagtail Form Builder functionalities available for your models/snippets.
We found that wagtail-model-forms demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Opengrep forks Semgrep to preserve open source SAST in response to controversial licensing changes.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.