title: How can I query and compare the values of a JSONbField on an object?
body: <p>I have a model that contains a jsonbfield, and need to query the values of the dictionary. Within a query, I need to ensure that all the values of the dictionary are <code>None</code>, or that the entire field is None.</p>
  
  <p>My model looks like:</p>
  
  <pre><code>MyModel(models.Model):
      date_created=DatetimeField()
      json_dict = JSONField(default=dict, null=True)
  </code></pre>
  
  <p>Essentially I want to get something like:</p>
  
  <pre><code>MyModel.objects.filter(Q(json_dict={}) |Q(json_dict=None) | Q(all(v=None for v in json_dict.values())))
  </code></pre>
  
  <p>The most important part being the</p>
  
  <pre><code>Q(all(v=None for v in json_dict.values()))
  </code></pre>
  
  <p>But I cannot do that in a query. I was wondering if there was a way to check this while keeping the results in a queryset, rather than evaluating it into a list and checking there.</p>
  
  <p>LIMITATIONS:</p>
  
  <ul>
  <li>I do not know the keys of the dictionary as they will be different for every object in MyModel.</li>
  <li>I must be able to use the <code>bulk_create</code> function, so overwriting save is not an option</li>
  </ul>