Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

198
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda