Вывести график Django, matplotlib, numpy
myAPP name catalog
I have models in models.py:
class Sale(models.Model):
good = models.ForeignKey ("Good", help_text = 'Select good', on_delete = models.SET_NULL, null = True)
quantitysales = models.IntegerField (default=1, help_text = 'Enter Qty')
datesales = models.DateField (null = True, blank = True)
storename = models.ForeignKey ("Store", help_text = 'Select store', on_delete = models.SET_NULL, null = True)
views.py пытаюсь написать функцию для вывода моей картинки, но не уверен, что делаю правильно
def sales_filter(request):
with connection.cursor() as cursor:
cursor.execute('''
select datesales, alcohol, confections
from catalog_Sale
where datesales = %s,
order by datesales;
''', ('2020-04-10',))
dt = np.array([ ( (x), float (y), float (z) ) for (x, y, z) in cursor ])
fig, ax = plt.subplots()
tm = np.array(dt[:,0])
alcohol = np.array([ x for x in accumulate(dt[:,1]) ])
confections = np.array([ x for x in accumulate(dt[:,2]) ])
ax.plot(tm,alcohol)
ax.plot(tm,confections)
#Generate image grafic
buf = io.BytesIO()
fig.savefig(buf,format='PNG')
return HttpResponse( buf.getvalue(), content_type='image/png')
My cod have error and i dont know if my cod its correct, i need help please!!!
Exception Value:
near ",": syntax error