示例#1
0
def add(request):
    if request.method == 'POST':
        form = SchoolForm(request.POST)
        if form.is_valid():
            school = form.save()
            status = "success"
            school_id = school.id
            return HttpResponse(json.dumps({'status':status,'school_id':school_id}))
    else:       
        form = SchoolForm()
    return render(request, 'schools_add_form.html', {'form' : form})
示例#2
0
def create_school(request):
    if request.method == 'POST':
        form = SchoolForm(request.POST)
        if form.is_valid:
            school = form.save(commit=False)
            school.save()
            school.members = [request.user,]
            return HttpResponseRedirect(reverse('school_list'))
    else:
        form = SchoolForm()
    return render(request, 'schools/school_form.html', {'form':form}, context_instance=RequestContext(request))
示例#3
0
def edit(request, school_id):
    school = School.objects.get(id = school_id)
    if request.method == 'POST':
        form = SchoolForm(request.POST, instance = school)
        if form.is_valid():
            school = form.save(commit=False)
            school.approved = True
            school.save()
            status="success"
            return HttpResponse(status)
    else:       
        form = SchoolForm(instance = school)
    return render(request, 'schools_edit_form.html', {'form' : form})