#26511: Django 1.9 and Postgres 9.4 jsonb string containment inside JSONField
----------------------------------+--------------------------------------
     Reporter:  eoinmurray        |                    Owner:
         Type:  Bug               |                   Status:  closed
    Component:  contrib.postgres  |                  Version:  1.9
     Severity:  Normal            |               Resolution:  worksforme
     Keywords:  postgres, jsonb   |             Triage Stage:  Unreviewed
    Has patch:  0                 |      Needs documentation:  0
  Needs tests:  0                 |  Patch needs improvement:  0
Easy pickings:  0                 |                    UI/UX:  0
----------------------------------+--------------------------------------

Comment (by charettes):

 As Claude pointed out the `textfield__contains` and `jsonfield__contains`
 lookups do not behave the same.

 In order to use the `textfield__contains` operator on `metadata ->
 'title'` field you'll have to cast your JSON field to text (just like you
 do in your `raw()` query) before hand.

 The following should work against the master branch (which introduced the
 `Cast` [https://docs.djangoproject.com/en/dev/ref/models/database-
 functions/#cast function]):

 {{{#!python
 from django.db import models

 File.objects.annotate(
     title=Cast('metadata__title', models.TextField()),
 ).filter(title__contains='moon')
 }}}

--
Ticket URL: <https://code.djangoproject.com/ticket/26511#comment:3>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/068.1927abb5d3a4af013148c372fe3129a4%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to