I have been working on a project, where the project has a Model called Competition and under each completion I have a model called Artwork ( in foreign key relationship). I am using DRF and the problem I am facing is each artwork has a field called approved ( boolean ) and I want to retrieve all the approved artwork under a competition detail view.
How can I filter that data on Competition retrieve API view. I could not find any good examples. Please help
Also, I have been thinking about making another API that will filter the artwork only based on the given competition id.
Please help me to find out the solution.
GET /api/v1/ongoing-competitions/
[
{
"id": "e1c0c058-1d8b-4e90-b2a6-6789cf897f08",
"name": "Competition one",
"description": "Competition one descriptions",
"thumnail": "https://static.wixstatic.com/media/c84c64_e6218cad44794b949661b0d88097182e~mv2.jpg/v1/fill/w_383,h_283,al_c,q_80,usm_0.66_1.00_0.01/IAS%20Gallery_Original.webp",
"created_at": "2020-07-22T12:46:53.938819Z",
"ended": false,
"artworks": [
{
"id": "b7916507-109d-41e2-b5b4-50c9fdc105c3",
"title": "Hello",
"medium": "Acrolic",
"dimension": "32x33",
"paid": false,
"approved": true,
"user": null,
"position": 0,
"created_at": "2020-07-22T14:23:24.047062Z",
"artist": {
"id": "54efb6a3-a746-4c3c-bdd2-77e09bdd5bb7",
"full_name": "Manas Paul",
"email": "imanaspaul@gmail.com",
"artist_website": "https://manascode.com",
"artist_biography": "He is the best artist",
"artist_statement": "Manas paul is great..",
"created_at": "2020-07-22T14:21:48.134035Z"
},
"competition": {
"id": "e1c0c058-1d8b-4e90-b2a6-6789cf897f08",
"name": "Competition one",
"description": "Competition one descriptions",
"thumnail": "https://static.wixstatic.com/media/c84c64_e6218cad44794b949661b0d88097182e~mv2.jpg/v1/fill/w_383,h_283,al_c,q_80,usm_0.66_1.00_0.01/IAS%20Gallery_Original.webp",
"ended": false,
"created_at": "2020-07-22T12:46:53.938819Z"
}
},
{
"id": "f758d846-f446-4f1a-bd4c-ae9271e3a9ce",
"title": "gdfg",
"medium": "gfdg",
"dimension": "gdfg",
"paid": false,
"approved": false,
"user": null,
"position": 1,
"created_at": "2020-07-22T14:24:37.008208Z",
"artist": {
"id": "54efb6a3-a746-4c3c-bdd2-77e09bdd5bb7",
"full_name": "Manas Paul",
"email": "imanaspaul@gmail.com",
"artist_website": "https://manascode.com",
"artist_biography": "He is the best artist",
"artist_statement": "Manas paul is great..",
"created_at": "2020-07-22T14:21:48.134035Z"
},
"competition": {
"id": "e1c0c058-1d8b-4e90-b2a6-6789cf897f08",
"name": "Competition one",
"description": "Competition one descriptions",
"thumnail": "https://static.wixstatic.com/media/c84c64_e6218cad44794b949661b0d88097182e~mv2.jpg/v1/fill/w_383,h_283,al_c,q_80,usm_0.66_1.00_0.01/IAS%20Gallery_Original.webp",
"ended": false,
"created_at": "2020-07-22T12:46:53.938819Z"
}
}
]
}
]
Second way ( I thought )
GET /api/v1/get-artsworks/:competition-id
And filter the artwork and return the response. But in this case, I have to call two endpoint at the same time from the frontend. So I am getting confused about which one is the best way to implement.