diff options
Diffstat (limited to 'grades/views.py')
-rw-r--r-- | grades/views.py | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/grades/views.py b/grades/views.py index 67844bd..48cd8e3 100644 --- a/grades/views.py +++ b/grades/views.py @@ -1,7 +1,8 @@ from django.shortcuts import render from django.contrib.auth.decorators import login_required from django.forms import inlineformset_factory -from grades.forms import GradingSystemForm +from django.contrib import messages +from grades.forms import GradingSystemForm, GradeRangeForm from grades.models import GradingSystem, GradeRange @@ -21,7 +22,7 @@ def add_grading_system(request, system_id=None): if system_id is not None: grading_system = GradingSystem.objects.get(id=system_id) GradeRangeFormSet = inlineformset_factory(GradingSystem, GradeRange, - fields='__all__', extra=0) + GradeRangeForm, extra=0) grade_form = GradingSystemForm(instance=grading_system) is_default = (grading_system is not None and grading_system.name == 'default') @@ -30,15 +31,16 @@ def add_grading_system(request, system_id=None): formset = GradeRangeFormSet(request.POST, instance=grading_system) grade_form = GradingSystemForm(request.POST, instance=grading_system) if grade_form.is_valid(): - system = grade_form.save(commit=False) - system.creator = user - system.save() - system_id = system.id - if formset.is_valid(): - formset.save() + grading_system = grade_form.save(commit=False) + grading_system.creator = user + grading_system.save() + system_id = grading_system.id + if formset.is_valid(): + formset.save() + messages.success(request, "Grading system saved successfully") if 'add' in request.POST: GradeRangeFormSet = inlineformset_factory( - GradingSystem, GradeRange, fields='__all__', extra=1 + GradingSystem, GradeRange, GradeRangeForm, extra=1 ) formset = GradeRangeFormSet(instance=grading_system) |