After using Django for 4 months and enjoying it, now I'm trying DRF. While it's suited for most of my needs, I found an issue and I don't know how to deal with.
Let's say I have a TrainTravel model, with fields such as: passengers, average_km_hour, arrival_timestamp, departure_timestamp, and so on.
It's easy to query DRF for all TrainTravel , or for just all Trains with at least 50 passengers or Trains with an average of 150km/h.
The problem is when I want to do big queries, and those queries will return fields that don't exist in the model of the database. I'll explain:
Let's say I want a query that returns the average of passengers by day on the last 2 months, grouped by day and the average km/hour.
With normal SQL I would query the database and just return 'average_passagers', 'average_km_hour_by_day' and 'datetime' (the actual fields are a random example). But in DRF I can:
1) Get all TrainTravel objects instances and manipulate the data with Python: Super slow if I've to pull every register on the database
2) Perform a raw query with SQL. The problem is that it doesn't correspond with any existing model in the API. And I create a new model for every query, it will create a new table in the database.
So, in short: Sometimes I want to perform queries in the database that don't return the same fields of any model (sometimes I get info from 3 tables), but I just want to return a Json from the query.
It is DRF for me in this case?