Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

212
Views
Agregue streamfield al índice de búsqueda en Wagtail

Lucho por agregar mi streamfield al índice de búsqueda de wagtail. Esto afecta tanto a los bloques disponibles como a los personalizados.

Por lo que encontré en la lista de correo, un bloque personalizado debería implementar get_searchable_content , que es lo que hacen todos los bloques.

aquí está mi modelo que me gustaría indexar:

 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)

Gracias por cualquier pista :)

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Dado que aún no ha configurado un motor de búsqueda, está utilizando el motor de base de datos predeterminado. Esto solo le permite buscar en los campos predeterminados, cualquier campo personalizado que desee usar en la búsqueda necesita un motor de búsqueda más avanzado. Esto se explica aquí .

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!