HStore Value__Contains in Django 1.8

I asked about this on Django.users but didn't answer. I recently updated to Django 1.8 to take advantage of the built-in HStore field support (not using django-hStore), but I ran into this problem. I'm not sure if this is a bug, or if there is an undocumented way to do this.

I am trying to find all the objects in a given model whose "values" in their HStore field contain characters. However, searching for "__contains" only works if there is an exact match between the searched element and its value.

From my own application (I've removed some of the query results to make this easier to read)

>>> query1
[<LanguageDatum: \xf0i, This (m), And, >, <LanguageDatum: hadi, This (f), AfgA, >, <LanguageDatum: -e, His, ArBah, >, '...(remaining elements truncated)...']
>>> query1.filter(multigloss__values__contains=["This"])
[]
>>> query1.filter(multigloss__values__contains=["This (f)"])
[<LanguageDatum: hadi, This (f), AfgA, >,  <LanguageDatum: \xf0i, This (f), ArAnz, >, '...(remaining elements truncated)...']
>>> query1.filter(multigloss__values__contains=["His"])
[<LanguageDatum: -e, His, ArBah, >, <LanguageDatum: -eh, His, ArBah, >, <LanguageDatum: -hu, His, Chd, >, <LanguageDatum: -u, His, Chd, > '...(remaining elements truncated)...']
>>> query1.filter(multigloss__values__contains=["Hi"])
[]

      

The expected result is that queries will return any data that has a "multigloss" value that contains a string, not just strings that are exactly the same.

The example in the documentation should also fail unless you include the full word "collie" (I haven't tested, this is a hypothetical result):

>>> Dog.objects.create(name='Rufus', data={'breed': 'labrador'})
>>> Dog.objects.create(name='Meg', data={'breed': 'collie', 'owner': 'Bob'})

>>> Dog.objects.filter(data__values__contains=['collie'])
[<Dog: Meg>]

>>>#Hypothesized example!
>>> Dog.objects.filter(data__values__contains=['coll'])
[]
>>>#Should have returned [Dog: Meg]

      

Is there a way to make the request I'm trying to make here, or did I find a bug?

+3


source to share





All Articles