How to create a very complicated route with DRF

102 Views Asked by At

I have 4 models: School, Class, Student, Address. I want to build an API like /api/schools/1/classes/2/students/3/address.

This example would return the address of student which has id 3, belongs to class 2 and school 1 (may be more complicated in the future).

In Java it can be done easily:

@GetMapping("/api/schools/{school-id}/classes/{class-id}/students/{student-id}/address")
public Address getAddressOf(path parameters) {
    return myService.doLookup(parameters);
}

But with DRF I don't even have any knowledge about how to achieve it since I'm very new to Python and DRF.

For now I just can write 4 ModelViewset corresponding with 4 models listed above to have very basic CRUD endpoints. How can I create my expected API?

0

There are 0 best solutions below