I have created a function in Django with the purpose that users download files after they fill some form. I want to count how many times is downloaded a file, now how many times is called function. And I want to show that number on my site. How do I do this?
This is my function...
def Only(request):
page_title = 'Title'
if request.method == "POST":
form = Form(request.POST, request.FILES)
if form.is_valid():
newdoc = request.FILES['file']
#some tasks
response = HttpResponse(
output, content_type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
response['Content-Disposition'] = 'attachment; filename=%s' % filename
return response
else:
form = Form()
return render(request, 'only.html', { 'form': form, 'page_title':page_title })
CodePudding user response:
You should create a new integer field in the table where the information of this form is saved. Then when someone fills the form and downloads the file you should update it with 1.
To show this field, first you should create a new post (or get) method to get the field value, and then, you should call this method when you load the page.