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

190
Vistas
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
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