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

188
Views
Using QuerySet.update() to update specific keys in nested JSONField

So let's say I have a Model defined as below:

from django.contrib.postgres.fields import JSONField
class Job(models.Model):
    ...
    json_data = JSONField(default=dict, blank=True)

The json_data field has a key named approval_coefficient with values ranging from 0 to 1. I want to update all the Jobs with json_data__approval_coefficient as 0.25 to 0.75 without firing any post_save Signals, in one Query. Basically, I want to use the .update() to work with JSONfield.

Job.objects.filter(json_data__approval_coefficient=0.25).update(json_data...)

This doesn't work. (There are maybe 50 more keys for each Job object in json_data field, and I don't want to touch/update them at all. I am just concerned with this specific key.)

Although, I can get all the jobs using the filter query, and loop through it and update each of the entries one by one. But, this does multiple Write queries to the DB, and also fires post_save signals, which is not what I want.

On doing some digging around, found this and this PR which was never merged in Django.

How to go about this?

Python 3.6.8 Django (2, 2, 0, 'final', 0)

over 4 years ago · Santiago Trujillo
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!