How to translate icontains in django to SQL statement? -


I want to get the top 5 of the sale price of every month .

So I put the code like this

  DIF query (request): django.db = connection.cursor () from the import connection cursor.exicute ("SELECT Product_style_id, sum total_p, yoga (total amount as integer)) by total_p DESC limit 5 product_style_id by order as jewelry_productorder group as total_a ") output = cursor.fetchall () variable = RequestContext ( Request, {'Production': Output,}) Return Render_to_props ('top 5.html', variables)  

Result each year Instead of the top 5 of each month's top five showing in the table.

So I put the code in such a way (like adding a WHERE block)

  def query (request): m = request.GET ['month'] y = Request.GET ['year'] d = str (y + '-' + m) django.db import connection cursor = connection.cursor () from cursor.execute ("select product_style_id, sum (price) total_p In total, the total_p DESC range 5 ", [d] output = cursor.fetchall () variable = RequestContext (request, {'Product') ': Output,} product_style_id by command% s as group start_ Return) render_to_response ('top5.html', variables)  

the result came like this

programming error / query

operator does not exist : Date ~~ Unknown Line 1:. .._ jewelry_productorder WHERE due_date total_a ........................................... .................................................. You may need to specify explicitly.

Please help me, what should I do ??

__ icontains can be written in SQL using Django ILIKE .

Example:

 Select  ... where some_column iLike '% some_string%'  

rewrite your query as you like Then:

  cursor.execute ("product_style_id, sum" total_p, sum (selection in form of cast (sum as integer)) from jewel_productorder where total_p DESC range 5 By product_style_id command DUE_DATE iLike% s as group total_a ", [" %%% if your DB has not supported ILIKE (as stated in the comment on my answer), then do something like this:  
  select ... Where short (some_column) is less like ('% some_string%')  

Note that using less, using a (index Your db can stop if you have an index on that column).

Also, note that DJGongo 1.1 added aggregation support, so you should be able to create a support group without raw SQL. Check:


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -