Home > Mobile >  How can I write this sql query in django orm?
How can I write this sql query in django orm?

Time:12-05

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;

CodePudding user response:

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

  • Related