Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

207
Vistas
Add streamfield to search index in Wagtail

I struggle to add my streamfield to the wagtail search index. This affects boths the available or the custom blocks.

From what I've found in the mailing list, a custom block should implement get_searchable_content which all blocks do.

here is my model which I'd like to index:

class BlogPage(Page):
    author = models.ForeignKey(User, on_delete=models.PROTECT)
    date = models.DateField("Post date")
    main_category = models.ForeignKey('blog.BlogCategory', related_name='main_category', default=1, on_delete=models.PROTECT)
    categories = ParentalManyToManyField('blog.BlogCategory', blank=True, related_name='categories')
    readtime = models.IntegerField(blank=True, null=True)
    subtitle = models.CharField(
        verbose_name=_('subtitle'),
        max_length=255,
        help_text=_("The page subtitle as you'd like it to be seen by the public - also the blog post teaser."),
    )
    body = StreamField([
        ('heading', general.TitleBlock()),
        ('paragraph', blocks.RichTextBlock()),
        ('image', general.FillImageChooserBlock()),
        ('subtitle', general.SubTitleBlock()),
        ('pullquote', general.PullQuoteBlock()),
        ('blockquote', general.BlockQuoteBlock()),
    ])
    cover = models.ForeignKey(
        'wagtailimages.Image',
        on_delete=models.PROTECT,
        related_name='+'
    )

    content_panels = Page.content_panels + [
        MultiFieldPanel([
            FieldPanel('subtitle'),
            FieldPanel('date'),
            FieldPanel('main_category', widget=forms.Select),
            FieldPanel('categories', widget=forms.CheckboxSelectMultiple),
            ImageChooserPanel('cover'),
            FieldPanel('author'),
        ], heading="Blog information"),
        StreamFieldPanel('body'),
    ]

    search_fields = Page.search_fields + [
        index.FilterField('date'),
        index.FilterField('main_category'),
        index.SearchField('body'),
        index.SearchField('subtitle'),
    ]

    def get_context(self, request):
        context = super().get_context(request)
        context['posts'] = BlogPage.objects.exclude(id=self.id).order_by('-date')[:10]
        return context

    def save(self, *args, **kwargs):
        if self.body.stream_data:
            self.readtime = read_time_as_minutes(self.body.stream_data)
        return super().save(*args, **kwargs)

thx for any hints :)

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Since you have not yet configured a search backend, you are using the default database backend. This only allows you to search the default fields, any custom fields you want to use in search need a more advanced search engine. This is explained here.

about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda