#model.py
from django.contrib.auth.models import User
from django.db import models
class WhitePaper(models.Model):
author = models.ForeignKey(User,editable=False)
#view.py
from django.newforms import form_for_model
from django.core.urlresolvers import reverse
from white_paper.models import WhitePaper
def create(request,template_name):
WhitePaperForm=form_for_model(WhitePaper)
if request.method == 'POST':
form = WhitePaperForm(request.POST)
if form.is_valid():
result=form.save(commit=False)
result.author = request.user
result.save()
return HttpResponseRedirect(reverse('submit_success'))
else:
return HttpResponseRedirect(reverse('submit_error'))
else:
return render_to_response(template_name,{"form":WhitePaperForm().as_table()})
#url.py
from django.conf.urls.defaults import *
from website.white_paper.views import create
from django.views.generic.simple import direct_to_template
urlpatterns = patterns('',
url(
r'^create/',
create,
{"template_name":"white_paper/whitepaper_form.html"},
"white_paper_create"
),
url(
r'^submit_success/',
direct_to_template,
{"template":"white_paper/submit_success.html"},
"submit_success"
),
url(
r'^submit_error/',
direct_to_template,
{"template":"white_paper/submit_error.html"},
"submit_error"
)
)
from django.contrib.auth.models import User
from django.db import models
class WhitePaper(models.Model):
author = models.ForeignKey(User,editable=False)
#view.py
from django.newforms import form_for_model
from django.core.urlresolvers import reverse
from white_paper.models import WhitePaper
def create(request,template_name):
WhitePaperForm=form_for_model(WhitePaper)
if request.method == 'POST':
form = WhitePaperForm(request.POST)
if form.is_valid():
result=form.save(commit=False)
result.author = request.user
result.save()
return HttpResponseRedirect(reverse('submit_success'))
else:
return HttpResponseRedirect(reverse('submit_error'))
else:
return render_to_response(template_name,{"form":WhitePaperForm().as_table()})
#url.py
from django.conf.urls.defaults import *
from website.white_paper.views import create
from django.views.generic.simple import direct_to_template
urlpatterns = patterns('',
url(
r'^create/',
create,
{"template_name":"white_paper/whitepaper_form.html"},
"white_paper_create"
),
url(
r'^submit_success/',
direct_to_template,
{"template":"white_paper/submit_success.html"},
"submit_success"
),
url(
r'^submit_error/',
direct_to_template,
{"template":"white_paper/submit_error.html"},
"submit_error"
)
)