Ejemplo n.º 1
0
def add_subject(request):
    if request.method == 'POST':
        form = SubjectForm(request.POST)
        if form.is_valid():
            form.save()
            subjects_list = Subject.objects.all()
            return render_to_response('subjects.html',{'subjects':subjects_list}, context_instance=RequestContext(request)) 
    else:
        form = SubjectForm()
    return render_to_response('subjects.html', {'form_new_subject':form}, context_instance = RequestContext(request))
Ejemplo n.º 2
0
def edit_subject(request, id_subject):
    subject = Subject.objects.get(pk = id_subject)
    if request.method == 'POST':
        form = SubjectForm(request.POST, instance = subject)
        if form.is_valid():
            form.save()
            subjects_list = Subject.objects.all()
            return render_to_response('subjects.html',{'subjects':subjects_list}, context_instance=RequestContext(request))
    else:
        form = SubjectForm(instance = subject)
    return render_to_response('subjects.html', {'form':form}, context_instance = RequestContext(request))