Hey there, I am attempting to move over a very basic PHP site that runs SELECT SQL queries based on user input to display some data from a MySQL database. Things started out well, but unfortunately I don’t know how to format the SQL to be able to be run within Django, as it runs queries combining from a database with 3 tables and a database view as well.
Here is an example of one of the database queries that is being run. Is it even possible to do such things in Django?
SELECT i.year, i.brand, i.desc, i.colour, i.size, i.mpn, i.url, COALESCE(DATE_FORMAT(i_eta.eta, '%M %Y'),'Unknown') as eta FROM i JOIN i_eta ON i_eta.mpn = i.mpn WHERE category LIKE 'kids' ORDER BY i.brand, i.desc, i.colour, FIELD(size, 'xxl','xl','l','ml','m','s','xs','xxs') DESC, size+0, size
What I have so far (not much unfortunately) would be:
query = i.objects.filter(category="kids").order_by('brand','desc','colour')
the i_eta is a view, and I don’t know how to combine that with the other query info. I am guessing it would roughly translate to:
I am hoping to avoid directly running SQL but am lost.