diff --git a/accounts/forms.py b/accounts/forms.py index cc99e1f..a6ed970 100644 --- a/accounts/forms.py +++ b/accounts/forms.py @@ -324,6 +324,14 @@ class ProfileUpdateForm(UserChangeForm): label="Address / city", ) + program = forms.ModelChoiceField( + queryset=Program.objects.all(), + widget=forms.Select( + attrs={"class": "browser-default custom-select form-control"} + ), + label="Program", + ) + class Meta: model = User fields = [ diff --git a/accounts/views.py b/accounts/views.py index c506498..2da75c6 100644 --- a/accounts/views.py +++ b/accounts/views.py @@ -420,6 +420,10 @@ def edit_student(request, pk): if form.is_valid(): form.save() + student = Student.objects.get(student_id=instance.id) + student.program = form.cleaned_data["program"] + student.save() + messages.success(request, ("Student " + full_name + " has been updated.")) return redirect("student_list") else: @@ -477,6 +481,7 @@ def delete_student(request, pk): messages.success(request, "Student has been deleted.") return redirect("student_list") +# REDUNDANT @login_required @admin_required def edit_program(request, pk): diff --git a/templates/accounts/edit_student.html b/templates/accounts/edit_student.html index 8a56495..25b7169 100644 --- a/templates/accounts/edit_student.html +++ b/templates/accounts/edit_student.html @@ -30,6 +30,7 @@ {{ form.gender|as_crispy_field }} {{ form.phone|as_crispy_field }} {{ form.address|as_crispy_field }} + {{ form.program|as_crispy_field }} diff --git a/templates/accounts/profile_single.html b/templates/accounts/profile_single.html index 32a76d6..cc38a78 100644 --- a/templates/accounts/profile_single.html +++ b/templates/accounts/profile_single.html @@ -38,11 +38,10 @@ Edit Profile -
{# had to name out of convention because it clashes with 'edit_[whatever]program', which directs to 'program/[id]/edit/ #} - - Change Program - +{# #} +{# Change Program#} +{# #} {% endif %} {% if user.is_lecturer %}