From db8fd8642f5dc082e068e48962383a4f512a1498 Mon Sep 17 00:00:00 2001 From: Keannu Bernasol Date: Tue, 18 Jul 2023 16:01:19 +0800 Subject: [PATCH] Add debug student account on migrate and added subjects to user serializer --- stude/accounts/models.py | 4 ++-- stude/accounts/serializers.py | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/stude/accounts/models.py b/stude/accounts/models.py index 0ce2968..191ea70 100644 --- a/stude/accounts/models.py +++ b/stude/accounts/models.py @@ -88,9 +88,9 @@ def create_superuser(sender, **kwargs): # year_level = '1st Year' # semester = '1st Semester' - if not CustomUser.objects.filter(username=username).exists(): + if not User.objects.filter(username=username).exists(): # Create the superuser with is_active set to False - user = CustomUser.objects.create( + user = User.objects.create_user( username=username, email=email, password=password, first_name=first_name, last_name=last_name) # Activate the superuser diff --git a/stude/accounts/serializers.py b/stude/accounts/serializers.py index 4036c84..7f70f5f 100644 --- a/stude/accounts/serializers.py +++ b/stude/accounts/serializers.py @@ -11,6 +11,7 @@ from django.contrib.auth.password_validation import validate_password from courses.models import Course from year_levels.models import Year_Level from semesters.models import Semester +from subjects.models import Subject from django.contrib.gis.geos import Point @@ -26,6 +27,8 @@ class CustomUserSerializer(BaseUserSerializer): many=False, slug_field='name', queryset=Year_Level.objects.all(), required=False, allow_null=True) semester = serializers.SlugRelatedField( many=False, slug_field='name', queryset=Semester.objects.all(), required=False, allow_null=True) + subjects = serializers.SlugRelatedField( + many=True, slug_field='name', queryset=Subject.objects.all(), required=False, allow_null=True) class Meta(BaseUserSerializer.Meta): model = CustomUser