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

228
Visualizações
How to get objects that contain a specific string

I want to retrieve objects that contain a specific string in their CharField.
In normal Python without Django, I can do this to check:

if "something" in string:
   pass

However, I don't know how to do so using .filter() in Django:

posts = Post.objects.filter(field = "string") # how can I do something like 'in' here?

I don't just want to get objects that have exactly the value as "string".

Please teach me how to retrieve objects that contain a specific string in Django using .filter().

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

0

You can use contains. This will do case-sensitive containment test.

Post.objects.filter(field__contains='string')

This will generate the following SQL query.

SELECT ... WHERE field LIKE '%string%'

See field lookups for more information.

over 4 years ago · Santiago Trujillo Relatório

0

posts = Post.objects.filter(field__icontains = "string")

Chack here details

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