diff --git a/accounts/forms.py b/accounts/forms.py index 5780e0d..a10fae1 100644 --- a/accounts/forms.py +++ b/accounts/forms.py @@ -6,7 +6,7 @@ from django.contrib.auth.forms import ( ) from django.contrib.auth.forms import PasswordResetForm from course.models import Program -from .models import User, Student, Parent, RELATION_SHIP, LEVEL +from .models import User, Student, Parent, RELATION_SHIP, LEVEL, GENDERS class StaffAddForm(UserCreationForm): @@ -167,6 +167,15 @@ class StudentAddForm(UserCreationForm): label="Last name", ) + gender = forms.CharField( + widget=forms.Select( + choices=GENDERS, + attrs={ + "class": "browser-default custom-select form-control", + }, + ), + ) + level = forms.CharField( widget=forms.Select( choices=LEVEL, @@ -230,6 +239,7 @@ class StudentAddForm(UserCreationForm): user.is_student = True user.first_name = self.cleaned_data.get("first_name") user.last_name = self.cleaned_data.get("last_name") + user.gender = self.cleaned_data.get("gender") user.address = self.cleaned_data.get("address") user.phone = self.cleaned_data.get("phone") user.email = self.cleaned_data.get("email") diff --git a/accounts/models.py b/accounts/models.py index cfe9692..4090e6c 100644 --- a/accounts/models.py +++ b/accounts/models.py @@ -55,7 +55,7 @@ class CustomUserManager(UserManager): return queryset -GENDERS_CHOICES = (("M", "Male"), ("F", "Female")) +GENDERS = (("M", "Male"), ("F", "Female")) class User(AbstractUser): @@ -63,9 +63,7 @@ class User(AbstractUser): is_lecturer = models.BooleanField(default=False) is_parent = models.BooleanField(default=False) is_dep_head = models.BooleanField(default=False) - gender = models.CharField( - max_length=1, choices=GENDERS_CHOICES, blank=True, null=True - ) + gender = models.CharField(max_length=1, choices=GENDERS, blank=True, null=True) phone = models.CharField(max_length=60, blank=True, null=True) address = models.CharField(max_length=60, blank=True, null=True) picture = models.ImageField( diff --git a/templates/accounts/add_student.html b/templates/accounts/add_student.html index 2a00bdf..bfa580a 100644 --- a/templates/accounts/add_student.html +++ b/templates/accounts/add_student.html @@ -36,6 +36,7 @@
{{ form.first_name|as_crispy_field }} {{ form.last_name|as_crispy_field }} + {{ form.gender|as_crispy_field }} {{ form.email|as_crispy_field }} {{ form.address|as_crispy_field }} {{ form.phone|as_crispy_field }} diff --git a/templates/registration/register.html b/templates/registration/register.html index b8e605f..6e7ace1 100644 --- a/templates/registration/register.html +++ b/templates/registration/register.html @@ -53,6 +53,10 @@ {{ form.last_name }}
+
+ + {{ form.gender }} +
{{ form.level }}