instead of 
model_instance.sub_date = timezone.now()

I suggest you to declare a default for that field in your model definition.
default = timezone.now()


On Thursday, 20 August 2015 23:41:05 UTC+3, Hugo Kitano wrote:
>
> Hi, I'm a beginner using Django, and I'm having trouble using model forms 
> to create instances of my model.
> When a user submits a form, the database saves nothing.  Here's my code 
> for the view
>
> def submit(request): 
>
> SubmissionForm = modelform_factory(Submission, fields=('sub_name', 
> 'sub_file'))
>
> if request.method == "POST": 
>
> form = SubmissionForm(request.POST)
>
> if form.is_valid():
>
> model_instance = form.save(commit=False)
>
> model_instance.sub_date = timezone.now()
>
> model_instance.save()
>
> return HttpResponseRedirect('http://localhost:8000/stats/') 
>
> else:
>
> form = SubmissionForm()
>
> return render(request, 'stats/submit.html', {'form': form})
>
>
> And here's my template:
>
>
> <h1> Submit form: </h1>
> <form action="/stats/" method="post">
> {% csrf_token %}
> {{ form.as_p }}
> <input type="submit" value="Submit" />
> </form>
>
>
> I'd appreciate any help. Thansk!
>
>
> Hugo
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2d6fc0d1-d64f-44e3-b8bd-57bf5169f856%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to