コード例 #1
0
ファイル: views.py プロジェクト: docodon/blog_app
def add_blog(request):
    if request.method == 'POST':
        form = BLOGENTRY(request.POST)
        if form.is_valid():
            form = form.cleaned_data
            a, b = Author(), Post()

            a.name, a.email = form['name'], form['email']

            if Author.objects.filter(email=form['name'],
                                     name=form['name']).count() == 0:
                a.save()

            b.title = form['title']
            b.date = timezone.now()
            b.author = a
            b.body = form['blog']
            b.save()

        return index(request)

    else:
        form = BLOGENTRY()

        return render(request, 'add_blog.html', {'form': form})
コード例 #2
0
ファイル: views.py プロジェクト: docodon/blogger
def add_blog(request) :
	
	if request.method=='POST':
		form=BLOGENTRY(request.POST)
		if form.is_valid() :
			form=form.cleaned_data
			A=Post(title=form['title'],body=form['blog'],date=timezone.now(),author=Author.objects.get(handle=request.user.username))
			try :
				A.save()
			except IntegrityError as e:
				return render(request,'add_blog.html',{'form':BLOGENTRY(),'error':e.message})
			return index(request)
		else :
			return render(request,'add_blog.html',{'form':BLOGENTRY(),'error':'something went wrong..'})
	else :
		return render(request,'add_blog.html',{'form':BLOGENTRY()})