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

221
Views
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 answers
Answer question

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 Report

0

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

Chack here details

over 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!