mirror of
https://github.com/lemeow125/StudE-Backend.git
synced 2025-06-29 00:35:45 +08:00
Added student_status model
This commit is contained in:
parent
7762f72ce2
commit
ed6a66e989
15 changed files with 143 additions and 13 deletions
27
stude/accounts/migrations/0002_studentstatus.py
Normal file
27
stude/accounts/migrations/0002_studentstatus.py
Normal file
|
@ -0,0 +1,27 @@
|
|||
# Generated by Django 4.2.2 on 2023-06-26 13:46
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('accounts', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='StudentStatus',
|
||||
fields=[
|
||||
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, primary_key=True, serialize=False, to=settings.AUTH_USER_MODEL)),
|
||||
('x_latitude', models.FloatField(null=True)),
|
||||
('y_latitude', models.FloatField(null=True)),
|
||||
('subject', models.CharField(max_length=100)),
|
||||
('year_level', models.CharField(choices=[('1st', '1st year'), ('2nd', '2nd year'), ('3rd', '3rd year'), ('4th', '4th year'), ('5th', '5th Year'), ('Irreg', 'Irregular')], max_length=50)),
|
||||
('semester', models.CharField(choices=[('1st', '1st semester'), ('2nd', '2nd semester')], max_length=50)),
|
||||
('timestamp', models.DateField(auto_now_add=True)),
|
||||
],
|
||||
),
|
||||
]
|
16
stude/accounts/migrations/0003_delete_studentstatus.py
Normal file
16
stude/accounts/migrations/0003_delete_studentstatus.py
Normal file
|
@ -0,0 +1,16 @@
|
|||
# Generated by Django 4.2.2 on 2023-06-26 14:03
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('accounts', '0002_studentstatus'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.DeleteModel(
|
||||
name='StudentStatus',
|
||||
),
|
||||
]
|
|
@ -14,15 +14,6 @@ def validate_student_id(value):
|
|||
|
||||
|
||||
class CustomUser(AbstractUser):
|
||||
def _get_upload_to(instance, filename):
|
||||
base_filename, file_extension = os.path.splitext(filename)
|
||||
# Convert filename to a slug format
|
||||
cleaned_filename = slugify(base_filename)
|
||||
# Get the student ID number
|
||||
student_id = str(instance.student_id_number)
|
||||
new_filename = f"{student_id}_{cleaned_filename}{file_extension}"
|
||||
return os.path.join('avatars', new_filename)
|
||||
|
||||
YEAR_LEVELS = (
|
||||
('1st', '1st year'),
|
||||
('2nd', '2nd year'),
|
||||
|
@ -35,6 +26,16 @@ class CustomUser(AbstractUser):
|
|||
('1st', '1st semester'),
|
||||
('2nd', '2nd semester'),
|
||||
)
|
||||
|
||||
def _get_upload_to(instance, filename):
|
||||
base_filename, file_extension = os.path.splitext(filename)
|
||||
# Convert filename to a slug format
|
||||
cleaned_filename = slugify(base_filename)
|
||||
# Get the student ID number
|
||||
student_id = str(instance.student_id_number)
|
||||
new_filename = f"{student_id}_{cleaned_filename}{file_extension}"
|
||||
return os.path.join('avatars', new_filename)
|
||||
|
||||
first_name = models.CharField(max_length=100)
|
||||
last_name = models.CharField(max_length=100)
|
||||
# Email inherited from base user class
|
||||
|
|
|
@ -1,15 +1,20 @@
|
|||
from djoser.serializers import UserCreateSerializer as BaseUserRegistrationSerializer
|
||||
from djoser.serializers import UserSerializer as BaseUserSerializer
|
||||
from accounts.models import CustomUser
|
||||
from student_status.serializers import StudentStatusSerializer
|
||||
|
||||
|
||||
class CustomUserSerializer(BaseUserSerializer):
|
||||
user_status = StudentStatusSerializer(
|
||||
source='studentstatus', read_only=True)
|
||||
|
||||
class Meta(BaseUserSerializer.Meta):
|
||||
model = CustomUser
|
||||
fields = '__all__'
|
||||
fields = ('username', 'email', 'password',
|
||||
'student_id_number', 'year_level', 'semester', 'avatar', 'is_banned', 'user_status')
|
||||
|
||||
|
||||
class UserRegistrationSerializer(BaseUserRegistrationSerializer):
|
||||
class Meta(BaseUserRegistrationSerializer.Meta):
|
||||
fields = ('username', 'email', 'password',
|
||||
'is_student', 'student_id_number', 'year_level', 'semester', 'avatar')
|
||||
'student_id_number', 'year_level', 'semester', 'avatar')
|
||||
|
|
|
@ -3,5 +3,5 @@ from django.urls import path, include
|
|||
|
||||
urlpatterns = [
|
||||
path('', include('djoser.urls')),
|
||||
path('', include('djoser.urls.authtoken'))
|
||||
path('', include('djoser.urls.authtoken')),
|
||||
]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue