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. For more options, visit https://groups.google.com/d/optout.