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

307
Views
Django, JSONField, filter for non empty list

I have a jsonfield

foo = JSONField(default=list)

I want to filter queryset so that foo has some data (not empty list)

I've tried

MyModel.objects.filter(foo__ne=[])  # doesn't seem to work
MyModel.objects.filter(foo__gt=[])  # seems to work but can't be sure if it's the right approach
over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

MyModel.objects.exclude(foo=[]))
over 4 years ago · Santiago Trujillo Report

0

You should be able to test inequality by negating equality using Q objects.

from django.db.models import Q

MyModel.objects.filter(~Q(foo=[]))
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!