How can I write this sql query in django orm?

Question:

I have a sql query that works like this, but I couldn’t figure out how to write this query in django. Can you help me ?

select datetime,
       array_to_json(array_agg(json_build_object(parameter, raw)))  as parameters
  from dbp_istasyondata
 group by 1
 order by 1;
Asked By: Fırat Badur

||

Answers:

You can use raw function of django orm. You can write your query like this:

YourModel.objects.raw('select * from your table'): #---> Change the model name and query

Answered By: Divya Prakash