mirror of
https://github.com/lemeow125/StudE-Backend.git
synced 2024-11-17 06:19:24 +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):
|
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 = (
|
YEAR_LEVELS = (
|
||||||
('1st', '1st year'),
|
('1st', '1st year'),
|
||||||
('2nd', '2nd year'),
|
('2nd', '2nd year'),
|
||||||
|
@ -35,6 +26,16 @@ class CustomUser(AbstractUser):
|
||||||
('1st', '1st semester'),
|
('1st', '1st semester'),
|
||||||
('2nd', '2nd 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)
|
first_name = models.CharField(max_length=100)
|
||||||
last_name = models.CharField(max_length=100)
|
last_name = models.CharField(max_length=100)
|
||||||
# Email inherited from base user class
|
# Email inherited from base user class
|
||||||
|
|
|
@ -1,15 +1,20 @@
|
||||||
from djoser.serializers import UserCreateSerializer as BaseUserRegistrationSerializer
|
from djoser.serializers import UserCreateSerializer as BaseUserRegistrationSerializer
|
||||||
from djoser.serializers import UserSerializer as BaseUserSerializer
|
from djoser.serializers import UserSerializer as BaseUserSerializer
|
||||||
from accounts.models import CustomUser
|
from accounts.models import CustomUser
|
||||||
|
from student_status.serializers import StudentStatusSerializer
|
||||||
|
|
||||||
|
|
||||||
class CustomUserSerializer(BaseUserSerializer):
|
class CustomUserSerializer(BaseUserSerializer):
|
||||||
|
user_status = StudentStatusSerializer(
|
||||||
|
source='studentstatus', read_only=True)
|
||||||
|
|
||||||
class Meta(BaseUserSerializer.Meta):
|
class Meta(BaseUserSerializer.Meta):
|
||||||
model = CustomUser
|
model = CustomUser
|
||||||
fields = '__all__'
|
fields = ('username', 'email', 'password',
|
||||||
|
'student_id_number', 'year_level', 'semester', 'avatar', 'is_banned', 'user_status')
|
||||||
|
|
||||||
|
|
||||||
class UserRegistrationSerializer(BaseUserRegistrationSerializer):
|
class UserRegistrationSerializer(BaseUserRegistrationSerializer):
|
||||||
class Meta(BaseUserRegistrationSerializer.Meta):
|
class Meta(BaseUserRegistrationSerializer.Meta):
|
||||||
fields = ('username', 'email', 'password',
|
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 = [
|
urlpatterns = [
|
||||||
path('', include('djoser.urls')),
|
path('', include('djoser.urls')),
|
||||||
path('', include('djoser.urls.authtoken'))
|
path('', include('djoser.urls.authtoken')),
|
||||||
]
|
]
|
||||||
|
|
|
@ -62,7 +62,7 @@ INSTALLED_APPS = [
|
||||||
'djoser',
|
'djoser',
|
||||||
'rest_framework.authtoken',
|
'rest_framework.authtoken',
|
||||||
'accounts',
|
'accounts',
|
||||||
|
'student_status',
|
||||||
]
|
]
|
||||||
|
|
||||||
MIDDLEWARE = [
|
MIDDLEWARE = [
|
||||||
|
|
0
stude/student_status/__init__.py
Normal file
0
stude/student_status/__init__.py
Normal file
3
stude/student_status/admin.py
Normal file
3
stude/student_status/admin.py
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
from django.contrib import admin
|
||||||
|
|
||||||
|
# Register your models here.
|
6
stude/student_status/apps.py
Normal file
6
stude/student_status/apps.py
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
from django.apps import AppConfig
|
||||||
|
|
||||||
|
|
||||||
|
class StudentStatusConfig(AppConfig):
|
||||||
|
default_auto_field = 'django.db.models.BigAutoField'
|
||||||
|
name = 'student_status'
|
29
stude/student_status/migrations/0001_initial.py
Normal file
29
stude/student_status/migrations/0001_initial.py
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
# Generated by Django 4.2.2 on 2023-06-26 14:03
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
initial = True
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('accounts', '0003_delete_studentstatus'),
|
||||||
|
]
|
||||||
|
|
||||||
|
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)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
]
|
0
stude/student_status/migrations/__init__.py
Normal file
0
stude/student_status/migrations/__init__.py
Normal file
28
stude/student_status/models.py
Normal file
28
stude/student_status/models.py
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
from django.db import models
|
||||||
|
from accounts.models import CustomUser
|
||||||
|
|
||||||
|
# Create your models here.
|
||||||
|
|
||||||
|
|
||||||
|
class StudentStatus(models.Model):
|
||||||
|
YEAR_LEVELS = (
|
||||||
|
('1st', '1st year'),
|
||||||
|
('2nd', '2nd year'),
|
||||||
|
('3rd', '3rd year'),
|
||||||
|
('4th', '4th year'),
|
||||||
|
('5th', '5th Year'),
|
||||||
|
('Irreg', 'Irregular'),
|
||||||
|
)
|
||||||
|
SEMESTERS = (
|
||||||
|
('1st', '1st semester'),
|
||||||
|
('2nd', '2nd semester'),
|
||||||
|
)
|
||||||
|
user = models.OneToOneField(
|
||||||
|
CustomUser, on_delete=models.CASCADE, primary_key=True)
|
||||||
|
x_latitude = models.FloatField(null=True)
|
||||||
|
y_latitude = models.FloatField(null=True)
|
||||||
|
subject = models.CharField(max_length=100)
|
||||||
|
year_level = models.CharField(
|
||||||
|
max_length=50, choices=CustomUser.YEAR_LEVELS)
|
||||||
|
semester = models.CharField(max_length=50, choices=CustomUser.SEMESTERS)
|
||||||
|
timestamp = models.DateField(auto_now_add=True)
|
9
stude/student_status/serializers.py
Normal file
9
stude/student_status/serializers.py
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
from rest_framework import serializers
|
||||||
|
from student_status.models import StudentStatus
|
||||||
|
|
||||||
|
|
||||||
|
class StudentStatusSerializer(serializers.ModelSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = StudentStatus
|
||||||
|
fields = ('x_latitude', 'y_latitude', 'subject',
|
||||||
|
'year_level', 'semester', 'timestamp')
|
3
stude/student_status/tests.py
Normal file
3
stude/student_status/tests.py
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
from django.test import TestCase
|
||||||
|
|
||||||
|
# Create your tests here.
|
3
stude/student_status/views.py
Normal file
3
stude/student_status/views.py
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
from django.shortcuts import render
|
||||||
|
|
||||||
|
# Create your views here.
|
Loading…
Reference in a new issue