codeselfstudy / codeselfstudy_django

https://codeselfstudy.com
BSD 3-Clause "New" or "Revised" License
1 stars 0 forks source link

Language queries don't work yet #18

Open j127 opened 3 years ago

j127 commented 3 years ago

When querying on Slack for CW puzzles, languages aren't taken into account in the Django queries.

The q query will be a dictionary with a languages key that holds a Python list. The structure is like this:

{'languages': ['fortran', 'cobol', 'raku'], 'source': 'codewars', 'difficulty': 3}

The relevant data is stored as JSONB in Postgres. An example raw SQL query is:

SELECT original_raw_data ->> 'languages'
FROM puzzles_puzzle
WHERE source='Codewars'
LIMIT 1;
-- ["javascript", "haskell", "python", "rust"]

The Django query should return a puzzle that includes all of the languages that in listed in the q query.

See the notes that will be in apps/puzzles/puzzles.py.

j127 commented 3 years ago

Check out 9:20 in this video for how to do queries on JSON fields: https://www.youtube.com/watch?v=LbdUpY1I1zg

j127 commented 3 years ago

If it requires raw queries, this SO answer might help: https://dba.stackexchange.com/a/162595