the default jsonfield field type for django is postgres only, but there's 
support for mysql 5.7 via a third party package 
https://github.com/adamchainz/django-mysql.  specifically 
https://django-mysql.readthedocs.io/en/latest/model_fields/json_field.html

On Friday, May 11, 2018 at 3:30:42 PM UTC-4, mark wrote:
>
> I have a model Document that has a json field "metadata" containing a 
> dictionary of different values. One example:
>
> {"Orientation": "Landscape", 
> "Address": "Bethany Home Road", 
> "Photo Type": "Many People", 
> "a boolean": false, 
> "Person": ["Sam Smith", "Hank Jones"], 
> "Date": "05/13/2018", 
> "Location": "Washington DC", 
> "Decade": "2020"}
>
> I can write a query to find all the record(s) in the Document table that 
> the "Person" field contains "Sam Smith" like this
>
> Document.objects.filter(metadata__Person__contains='Sam Smith')
>
> Is there a way to write a query to find all the Documents that have "Sam*" 
> in the metadata field? 
>
> For example, if there were another document that had "Sammy Jacobs" in the 
> "Person" field, the query would return both that record and the record with 
> the "Sam Smith" in the Person field. 
>
> Either some sort of "or" condition within the query that would allow me to 
> search for "Sam Smith" or "Sammy Jacobs". Or, some sort of regex that I can 
> put in for the search criteria that says search for all the "Sam*" 
> occurrences in the "Person" list.
>
> I have been googling for a solution, but have not found one yet.
>
> Thanks!
>
> Mark
>
>  
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/cf094ca1-2d79-4f00-a264-81102fc32f01%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to