Good afternoon friends I have a slight problem, and I do not see the solution, I'm trying to save a search value by rank of fronts in the database using a form, all right, but when I try to save it gives me this error :
'FiltroFechas' object has no attribute 'save'
I've seen some solutions and it's changing the class in form.py
to ModelForm but I really do not want to use a model but my own form
I leave you my view.py
and my template, thanks in advance
view.py
def inicio(request):
plan_gral = jovenclub.objects.aggregate(sum=Sum('plan_gral'))
juridic_gral = ingresos.objects.aggregate(sum=Sum('juridico'))
natural_gral = ingresos.objects.aggregate(sum=Sum('natural'))
general = juridic_gral['sum']+natural_gral['sum']
porciento_general = general*100/plan_gral['sum']
ingreso = ingresos.objects.all()
if request.method == "POST":
formulario = FiltroFechas(request.POST)
if formulario.is_valid():
consulta = formulario.save(commit=False)
consulta.hasta = timezone.now()
consulta.save()
else:
formulario = FiltroFechas()
args = {}
args.update(csrf(request))
args['form'] = formulario
return render_to_response('index.html', {'form': formulario, 'porciento':porciento_general, 'general':general, 'plan_gral':plan_gral,'suma':plan_gral['sum'],'juridico':juridic_gral['sum'], 'ingreso':ingreso, 'natural':natural_gral['sum']}, context_instance=RequestContext(request))
index.html
<form action="" method="POST"> {% csrf_token %}
Desde:{{ form.desde }} Hasta:{{ form.hasta }}<br/>
<input type = "submit" name = "submit" value = "Ver resultados">
</form>
Form.py
# encoding:utf-8
from django.forms import ModelForm
from django import forms
from principal.models import jovenclub
from functools import partial
DateInput = partial(forms.DateInput, {'class':'form-control bs-datepicker'})
class FiltroFechas(forms.Form):
desde = forms.DateField(widget=DateInput())
hasta = forms.DateField(widget=DateInput())