Beispiel #1
0
def question(request):
    c = {}
    c.update(csrf(request))
    errors = []
    catlist = Categories.objects.all().order_by("catname")
    if request.method == 'POST':
        if not request.POST.get('title', ''):
            errors.append('Enter a title.')
        if not request.POST.get('message', ''):
            errors.append('Enter a message.')
	if not int(request.POST.get('catid', '')):
            errors.append('Chose category.')
        if not errors:
	    catid = int(request.POST.get('catid'))
	    title = request.POST.get('title')
	    message = request.POST.get('message')
	    new_question = Questions(title = title, question = message, category_id = catid)
            new_question.save()
            return HttpResponseRedirect('/question/')
    return render_to_response('question.html',
        {'errors': errors, 'catlist': catlist})