Ejemplo n.º 1
0
def add_course(request):
    if request.method == 'POST':
        form = CourseForm(request.POST)
        if form.is_valid():
            form.save()
            courses_list = Course.objects.all()
            return render_to_response('courses.html',{'courses':courses_list}, context_instance=RequestContext(request)) 
    else:
        form = CourseForm()
    return render_to_response('courses.html', {'form':form}, context_instance = RequestContext(request))
Ejemplo n.º 2
0
def edit_course(request, id_course):
    course = Course.objects.get(pk = id_course)
    if request.method == 'POST':
        form = CourseForm(request.POST, instance = course)
        if form.is_valid():
            form.save()
            courses_list = course.objects.all()
            return render_to_response('courses.html',{'courses':courses_list}, context_instance=RequestContext(request))
    else:
        form = CourseForm(instance = course)
    return render_to_response('courses.html', {'form':form}, context_instance = RequestContext(request))