1

I have a model, which has JSON field called data. I need to query all models, which have type in this data field, which starts with string gpa.

Corresponding query is:

select data ->> 'type' from model where data ->> 'type' like 'gpa.%'

How can I do this using querysets? All I could find is an exact match, not startswith. I am using django 1.18

1 Answer 1

1

I assume that you have data jsonfield, and you are searching value of key named type starts with 'gpa.'.You can try this:

Model.objects.filter(data__type__startswith='gpa.')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.