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

226
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

0

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

Chack here details

over 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