wagtail-streamfield

Wagtail SnippetChooserBlock in Streamfield

主宰稳场 提交于 2021-02-07 08:58:33
问题 I am having some trouble getting the values from a snippet, that I have included into a streamfield using a Snippet Chooser Block. BioSnippet: @register_snippet class BioSnippet(models.Model): name = models.CharField(max_length=200, null=True) job_title = models.CharField(max_length=200, null=True, blank=True) bio = RichTextField(blank=True) image = models.ForeignKey( 'wagtailimages.Image', null=True, blank=True, on_delete=models.SET_NULL, related_name='+', verbose_name='Bio Image' ) contact

Wagtail SnippetChooserBlock in Streamfield

[亡魂溺海] 提交于 2021-02-07 08:57:16
问题 I am having some trouble getting the values from a snippet, that I have included into a streamfield using a Snippet Chooser Block. BioSnippet: @register_snippet class BioSnippet(models.Model): name = models.CharField(max_length=200, null=True) job_title = models.CharField(max_length=200, null=True, blank=True) bio = RichTextField(blank=True) image = models.ForeignKey( 'wagtailimages.Image', null=True, blank=True, on_delete=models.SET_NULL, related_name='+', verbose_name='Bio Image' ) contact

Creating a TagsBlock for StreamField

允我心安 提交于 2020-04-18 05:48:05
问题 I'm trying to create a struck block, which has a tags field so the user could choose the tags he wants to filter from. I created the tags field using wagtail.admin.widgets import AdminTagWidget . class TagsBlock(FieldBlock): field = forms.CharField( widget=AdminTagWidget ) class RelatedArticlesBlock(StructBlock): title = CharBlock(required=False) filter_tags = TagsBlock() no_of_items = IntegerBlock() It works as expected for selecting tags. But when I save it gives validation errors because

Converting class object to readable value for get_api_representation function

[亡魂溺海] 提交于 2020-01-03 17:34:29
问题 Previous topic where I was kindly helped by @gasman so i have a model class ingredients like: @register_model_chooser class Ingredient(models.Model): name = models.CharField(max_length=255) def __str__(self): return self.name and to represent this in API i created this class: class IngredientChooserBlock(ModelChooserBlock): def get_api_representation(self, value, context=None): if value: return { 'name': value.name, } then i have another model class that uses IngredientChooserBlock class:

Converting class object to readable value for get_api_representation function

雨燕双飞 提交于 2020-01-03 17:33:13
问题 Previous topic where I was kindly helped by @gasman so i have a model class ingredients like: @register_model_chooser class Ingredient(models.Model): name = models.CharField(max_length=255) def __str__(self): return self.name and to represent this in API i created this class: class IngredientChooserBlock(ModelChooserBlock): def get_api_representation(self, value, context=None): if value: return { 'name': value.name, } then i have another model class that uses IngredientChooserBlock class:

Wagtail getting/generating image urls from JSON api or directly

天涯浪子 提交于 2019-12-22 08:53:00
问题 I've been using Wagtail as a headless CMS to use with a frontend application, However I noticed some limitations regarding images. Normally in your jinja template you would generate the correct image size you need and all is fine, However I don't have access to these helpers in my frontend code. I have been trying several things. for example, to solve this for simple page models and their fields I could render a custom api field like so: api_fields = [ # Adds information about the source

Access StructBlock in a StreamField of a Page.get_children in Wagtail

拈花ヽ惹草 提交于 2019-12-13 03:54:24
问题 I try to render a StreamField of a child page in a Page. I don't manage to render the different StructField within the StreamField. Here is my code class DefinitionPage(Page): body = StreamField([ ('definition', blocks.StructBlock([ ('heading', blocks.CharBlock(label='Titre')), ('paragraph', blocks.RichTextBlock(label='Paragraphe')), ])) ]) content_panels = Page.content_panels + [ StreamFieldPanel('body'), ] my template. (DefinitionPage is a child of this page.) {% for post in page.get

Implement Wagtail ListBlock module with min/max children

痴心易碎 提交于 2019-12-11 06:06:45
问题 I'm building a new block type for use in the StreamField. It's called an FAQModule and it should allow a title and 1 or more question/answer pairs. class FAQBlock(blocks.StructBlock): headline = blocks.TextBlock(help_text="Enter headline / question") text = blocks.TextBlock(help_text="Enter a description / answer ") class FAQCardsWithListBlock(blocks.StructBlock): title = blocks.TextBlock(help_text="Enter FAQ title") questions = blocks.ListBlock(FAQBlock()) class Meta: label = 'FAQ Block'

Can't edit Streamfield page after 2.5 upgrade

南笙酒味 提交于 2019-12-11 01:44:16
问题 I have a site in local dev using Streamfield and 2 custom StructBlock fields. Works fine in 2.4 but after upgrading to 2.5 I can create the page fine in the admin but when I go to edit that page in the admin after saving it get an error. I tried with a fresh database as well but got the same error. Front end of the page works fine. Start a new project with wagtail start myproject Create a streamfield page with a custom StructBlock field. (Perhaps even just a built in field, haven't tested

content_panels in StreamBlock StreamField

时光总嘲笑我的痴心妄想 提交于 2019-12-10 18:25:10
问题 I have a few custom StreamField blocks defined. I'd like the option to be able to collapse some properties within the custom blocks much like i can do with a standard page model using content_panels however I don't believe this is supported. Correct? 回答1: It does not appear that this is possible without writing some custom css/js for your admin pages. There is one work around solution for collapsing one StreamFieldPanel inside a standalone MultiFieldPanel , however this is not for blocks