The code seems right. Probably your form has some error. Try print {{form.errors}} in your template to check.
On Thu, Aug 20, 2015 at 4:45 PM, Hugo Kitano <hkitan...@gmail.com> 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 django-users+unsubscr...@googlegroups.com. > To post to this group, send email to django-users@googlegroups.com. > 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/af4016f0-65e5-4a5c-99e9-7f544e7ced7c%40googlegroups.com > <https://groups.google.com/d/msgid/django-users/af4016f0-65e5-4a5c-99e9-7f544e7ced7c%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- 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 django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. 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/CAGjPPHn0f-rdRKDd4J9sA%3DVbH4R7zTvyPmMYv-dCb80%3DiLq%2Bsg%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.