Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

362
Visualizações
SearchVectorField - joined reference not allowed for taggit field

My model definition is as follows (a simplified model of the one being used in actual product. There are a coupe of other fields:

from django.db import models
from taggit.managers import TaggableManager

from django.contrib.postgres.search import SearchVectorField
from django.contrib.postgres.indexes import GinIndex

class Product(models.Model):
    tags = TaggableManager()
    search_vector = SearchVectorField(null=True)

    class Meta:
        indexes = [
            GinIndex(fields=['search_vector'])
        ]

I run make migrations and migrate commands. These work correctly.

I then run the following set of commands to build the index:

search_vector = SearchVector('tags__name')
Product.objects.all().update(search_vector=search_vector)

I end up getting the following error:

django.core.exceptions.FieldError: Joined field references are not permitted in this query

This is clearly caused by the tags__name field, but I am not sure how to solve it.

Can someone please explain what I would need to do in order to run the above commands correctly?

Thanks!

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

It cannot be done this way.

A possible approach is to write custom triggers using self-made migration. Triggers would look into table tag and update the index search_vector on each action of these:

  • INSERT into product,
  • INSERT into tag,
  • UPDATE tag,
  • DELETE from tag,
  • Updating Product's tags.

Looks like a real mess? So it is. Here you can see one guy tried this approach.

I'd suggest a more straightforward way. You can add product.tags_for_search TextField, which would be maintained manually.

  • Let's refuse the deletion of tags. They can be marked DELETED, so we wouldn't need to update product.tags_for_search when a tag is deleted.
  • If we need to rename a tag and remain all the relations, we just can add one and copy all the relations.
  • For inserting entries of product everything is fine, you just need to set a proper field value, same goes for updating a set of tags.

Your goal seems quite achievable for me this way.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda