1

I use mysql table as temporary storage of my data that I parse. I've tried to get data from the table, save it to variables, delete rows from table and bring model's objects (that were saved to the variables) to template, but unsuccessful. QuerySet are lazy, but I want to get data from table, not only pointers. How I could do this?

fop_rating = Edata.objects.values('recipt_name').filter(recipt_edrpou='xxxxxxxxxx').annotate(total=Sum('amount')).order_by('-total')[:10]

uric_rating = Edata.objects.values('recipt_name').exclude(recipt_edrpou='xxxxxxxxxx').annotate(total=Sum('amount')).order_by('-total')[:10]

rows = Edata.objects.filter(rand_ind=rand_ind)  
for r in rows: # delete all the rows
    r.delete()

return render(request,'edata/index.html',{"data":data,'fop_rating':fop_rating,'uric_rating':uric_rating})

1 Answer 1

3

Your code needs a slight change.

resp  = render(request,'edata/index.html',
  {"data":data,'fop_rating':fop_rating,'uric_rating':uric_rating})

Edata.objects.filter(rand_ind=rand_ind).delete()

return resp

note that you need to render the response before rows are deleted. Secondly you don't need to delete it row by row (that would be rather inefficient). You can bulk delete as above.

Sign up to request clarification or add additional context in comments.

1 Comment

Glad to have been of help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.