mirror of
https://github.com/lemeow125/InfoTech-Backend.git
synced 2024-11-16 22:19:25 +08:00
Added time schedule model
This commit is contained in:
parent
864643278c
commit
1b02c8f3c6
20 changed files with 193 additions and 21 deletions
|
@ -6,5 +6,6 @@ urlpatterns = [
|
||||||
path('', include('students.urls')),
|
path('', include('students.urls')),
|
||||||
path('', include('professors.urls')),
|
path('', include('professors.urls')),
|
||||||
path('', include('schedules.urls')),
|
path('', include('schedules.urls')),
|
||||||
|
path('', include('timeslots.urls')),
|
||||||
path('accounts/', include('accounts.urls')),
|
path('accounts/', include('accounts.urls')),
|
||||||
]
|
]
|
||||||
|
|
|
@ -47,6 +47,7 @@ INSTALLED_APPS = [
|
||||||
'students',
|
'students',
|
||||||
'professors',
|
'professors',
|
||||||
'schedules',
|
'schedules',
|
||||||
|
'timeslots',
|
||||||
]
|
]
|
||||||
|
|
||||||
MIDDLEWARE = [
|
MIDDLEWARE = [
|
||||||
|
@ -156,3 +157,5 @@ EMAIL_PORT = '2525'
|
||||||
|
|
||||||
CORS_ALLOW_ALL_ORIGINS = True
|
CORS_ALLOW_ALL_ORIGINS = True
|
||||||
CORS_ALLOW_CREDENTIALS = True
|
CORS_ALLOW_CREDENTIALS = True
|
||||||
|
|
||||||
|
TIME_INPUT_FORMATS = ['%I:%M %p',]
|
||||||
|
|
|
@ -26,3 +26,6 @@ class StudentSchedule(models.Model):
|
||||||
student_assigned = models.ForeignKey(
|
student_assigned = models.ForeignKey(
|
||||||
'students.Student', on_delete=models.CASCADE)
|
'students.Student', on_delete=models.CASCADE)
|
||||||
date_joined = models.DateTimeField(default=now, editable=False)
|
date_joined = models.DateTimeField(default=now, editable=False)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.schedule
|
||||||
|
|
|
@ -23,13 +23,3 @@ class ScheduleSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
fields = ('id', 'subject', 'students_assigned',
|
fields = ('id', 'subject', 'students_assigned',
|
||||||
'professor', 'date_created')
|
'professor', 'date_created')
|
||||||
read_only_fields = ('id', 'date_created')
|
read_only_fields = ('id', 'date_created')
|
||||||
|
|
||||||
|
|
||||||
class StudentScheduleSerializer(serializers.HyperlinkedModelSerializer):
|
|
||||||
date_joined = serializers.DateTimeField(
|
|
||||||
format="%d-%m-%Y %I:%M%p", read_only=True)
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = Schedule
|
|
||||||
fields = ('id', 'schedule', 'student_assigned', 'date_joined')
|
|
||||||
read_only_fields = ('id', 'date_joined')
|
|
||||||
|
|
|
@ -9,5 +9,4 @@ router.register(r'schedules', views.ScheduleViewSet)
|
||||||
# Additionally, we include login URLs for the browsable API.
|
# Additionally, we include login URLs for the browsable API.
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('', include(router.urls)),
|
path('', include(router.urls)),
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|
|
@ -3,7 +3,7 @@ from django.shortcuts import render
|
||||||
# Create your views here.
|
# Create your views here.
|
||||||
from rest_framework.permissions import IsAuthenticated
|
from rest_framework.permissions import IsAuthenticated
|
||||||
from rest_framework import viewsets
|
from rest_framework import viewsets
|
||||||
from .serializers import ScheduleSerializer, StudentScheduleSerializer
|
from .serializers import ScheduleSerializer
|
||||||
from .models import Schedule, StudentSchedule
|
from .models import Schedule, StudentSchedule
|
||||||
|
|
||||||
|
|
||||||
|
@ -11,9 +11,3 @@ class ScheduleViewSet(viewsets.ModelViewSet):
|
||||||
# permission_classes = [IsAuthenticated]
|
# permission_classes = [IsAuthenticated]
|
||||||
serializer_class = ScheduleSerializer
|
serializer_class = ScheduleSerializer
|
||||||
queryset = Schedule.objects.all()
|
queryset = Schedule.objects.all()
|
||||||
|
|
||||||
|
|
||||||
class StudentScheduleViewSet(viewsets.ModelViewSet):
|
|
||||||
# permission_classes = [IsAuthenticated]
|
|
||||||
serializer_class = StudentScheduleSerializer
|
|
||||||
queryset = StudentSchedule.objects.all()
|
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
# Generated by Django 4.2 on 2023-04-22 05:08
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('students', '0009_student_full_name'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='student',
|
||||||
|
name='current_semester',
|
||||||
|
field=models.CharField(choices=[('1st Semester', 'First Sem'), ('2nd Semester', 'Second Sem')], default='1st Semester', max_length=20),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='student',
|
||||||
|
name='year_level',
|
||||||
|
field=models.CharField(choices=[('1st Year', 'First Year'), ('2nd Year', 'Second Year'), ('3rd Year', 'Third Year'), ('IU-Y4', '4th Year')], max_length=20),
|
||||||
|
),
|
||||||
|
]
|
19
infotech/students/migrations/0011_student_schedules.py
Normal file
19
infotech/students/migrations/0011_student_schedules.py
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
# Generated by Django 4.2 on 2023-04-22 05:25
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('schedules', '0002_alter_schedule_professor'),
|
||||||
|
('students', '0010_alter_student_current_semester_and_more'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='student',
|
||||||
|
name='schedules',
|
||||||
|
field=models.ManyToManyField(related_name='StudentSchedule_subject', through='schedules.StudentSchedule', to='schedules.schedule'),
|
||||||
|
),
|
||||||
|
]
|
|
@ -37,8 +37,9 @@ class Student(models.Model):
|
||||||
clearance_done = models.BooleanField()
|
clearance_done = models.BooleanField()
|
||||||
pta_done = models.BooleanField()
|
pta_done = models.BooleanField()
|
||||||
#
|
#
|
||||||
# schedules = models.ManyToManyField(
|
schedules = models.ManyToManyField(
|
||||||
# 'schedules.Schedule', related_name='StudentSchedule_subject', through='schedules.StudentSchedule')
|
'schedules.Schedule', related_name='StudentSchedule_subject', through='schedules.StudentSchedule')
|
||||||
|
#
|
||||||
year_level = models.CharField(max_length=20, choices=YearLevels.choices)
|
year_level = models.CharField(max_length=20, choices=YearLevels.choices)
|
||||||
current_semester = models.CharField(
|
current_semester = models.CharField(
|
||||||
max_length=20, choices=Semesters.choices, default=Semesters.FIRST_SEM)
|
max_length=20, choices=Semesters.choices, default=Semesters.FIRST_SEM)
|
||||||
|
|
|
@ -5,6 +5,8 @@ from schedules.models import Schedule
|
||||||
|
|
||||||
|
|
||||||
class StudentSerializer(serializers.HyperlinkedModelSerializer):
|
class StudentSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
|
schedules = serializers.SlugRelatedField(
|
||||||
|
queryset=Schedule.objects.all(), slug_field='schedule_subject', allow_null=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Student
|
model = Student
|
||||||
|
@ -13,6 +15,6 @@ class StudentSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
'address', 'birthplace',
|
'address', 'birthplace',
|
||||||
'mother_name', 'father_name',
|
'mother_name', 'father_name',
|
||||||
'registrar_done', 'clearance_done', 'pta_done',
|
'registrar_done', 'clearance_done', 'pta_done',
|
||||||
'year_level', 'current_semester'
|
'schedules', 'year_level', 'current_semester'
|
||||||
]
|
]
|
||||||
read_only_fields = ['id', 'full_name']
|
read_only_fields = ['id', 'full_name']
|
||||||
|
|
0
infotech/timeslots/__init__.py
Normal file
0
infotech/timeslots/__init__.py
Normal file
6
infotech/timeslots/admin.py
Normal file
6
infotech/timeslots/admin.py
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
from django.contrib import admin
|
||||||
|
from .models import TimeSchedule, TimeSlot
|
||||||
|
|
||||||
|
# Register your models here.
|
||||||
|
admin.register(TimeSlot)
|
||||||
|
admin.register(TimeSchedule)
|
6
infotech/timeslots/apps.py
Normal file
6
infotech/timeslots/apps.py
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
from django.apps import AppConfig
|
||||||
|
|
||||||
|
|
||||||
|
class TimeslotsConfig(AppConfig):
|
||||||
|
default_auto_field = 'django.db.models.BigAutoField'
|
||||||
|
name = 'timeslots'
|
33
infotech/timeslots/migrations/0001_initial.py
Normal file
33
infotech/timeslots/migrations/0001_initial.py
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
# Generated by Django 4.2 on 2023-04-22 05:25
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
initial = True
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='TimeSlot',
|
||||||
|
fields=[
|
||||||
|
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('name', models.TextField()),
|
||||||
|
('time_start', models.TimeField(max_length=40)),
|
||||||
|
('time_end', models.TimeField(max_length=20)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='TimeSchedule',
|
||||||
|
fields=[
|
||||||
|
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('name', models.TextField()),
|
||||||
|
('day', models.TextField(choices=[('Monday', 'M'), ('Tuesday', 'T'), ('Wednesday', 'W'), ('Thursday', 'Th'), ('Friday', 'F'), ('Saturday', 'S'), ('Sunday', 'Sn')])),
|
||||||
|
('time_window', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='timeslots.timeslot')),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
]
|
0
infotech/timeslots/migrations/__init__.py
Normal file
0
infotech/timeslots/migrations/__init__.py
Normal file
40
infotech/timeslots/models.py
Normal file
40
infotech/timeslots/models.py
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
from django.db import models
|
||||||
|
from django.core.validators import MaxValueValidator, MinValueValidator
|
||||||
|
from django.utils.timezone import now
|
||||||
|
# Create your models here.
|
||||||
|
|
||||||
|
|
||||||
|
class TimeSlot(models.Model):
|
||||||
|
name = models.TextField()
|
||||||
|
time_start = models.TimeField(max_length=40)
|
||||||
|
time_end = models.TimeField(max_length=20)
|
||||||
|
|
||||||
|
def save(self, *args, **kwargs):
|
||||||
|
self.name = f"{self.time_start} - {self.time_end}"
|
||||||
|
super().save(*args, **kwargs)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.name
|
||||||
|
|
||||||
|
|
||||||
|
class TimeSchedule(models.Model):
|
||||||
|
class Days(models.TextChoices):
|
||||||
|
Monday = 'Monday'
|
||||||
|
Tuesday = 'Tuesday'
|
||||||
|
Wednesday = 'Wednesday'
|
||||||
|
Thursday = 'Thursday'
|
||||||
|
Friday = 'Friday'
|
||||||
|
Saturday = 'Saturday'
|
||||||
|
Sunday = 'Sunday'
|
||||||
|
|
||||||
|
name = models.TextField()
|
||||||
|
day = models.TextField(choices=Days.choices)
|
||||||
|
time_window = models.ForeignKey(
|
||||||
|
TimeSlot, on_delete=models.CASCADE)
|
||||||
|
|
||||||
|
def save(self, *args, **kwargs):
|
||||||
|
self.name = f"{self.day} - {self.time_window}"
|
||||||
|
super().save(*args, **kwargs)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.name
|
20
infotech/timeslots/serializers.py
Normal file
20
infotech/timeslots/serializers.py
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
from rest_framework import serializers
|
||||||
|
from django.contrib.auth.models import User
|
||||||
|
from .models import TimeSlot, TimeSchedule
|
||||||
|
|
||||||
|
|
||||||
|
class TimeSlotSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = TimeSlot
|
||||||
|
fields = ('id', 'name', 'time_start', 'time_end')
|
||||||
|
read_only_fields = ['id', 'name']
|
||||||
|
|
||||||
|
|
||||||
|
class TimeScheduleSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
|
time_window = serializers.SlugRelatedField(
|
||||||
|
queryset=TimeSlot.objects.all(), slug_field='name')
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = TimeSchedule
|
||||||
|
fields = ('id', 'name', 'day', 'time_window')
|
||||||
|
read_only_fields = ['id', 'name']
|
3
infotech/timeslots/tests.py
Normal file
3
infotech/timeslots/tests.py
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
from django.test import TestCase
|
||||||
|
|
||||||
|
# Create your tests here.
|
12
infotech/timeslots/urls.py
Normal file
12
infotech/timeslots/urls.py
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
from django.urls import include, path
|
||||||
|
from rest_framework import routers
|
||||||
|
from . import views
|
||||||
|
|
||||||
|
router = routers.DefaultRouter()
|
||||||
|
router.register(r'timeslots', views.TimeSlotViewSet)
|
||||||
|
router.register(r'timeschedules', views.TimeScheduleViewSet)
|
||||||
|
# Wire up our API using automatic URL routing.
|
||||||
|
# Additionally, we include login URLs for the browsable API.
|
||||||
|
urlpatterns = [
|
||||||
|
path('', include(router.urls)),
|
||||||
|
]
|
17
infotech/timeslots/views.py
Normal file
17
infotech/timeslots/views.py
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
from rest_framework import viewsets, generics
|
||||||
|
from .models import TimeSlot, TimeSchedule
|
||||||
|
from .serializers import TimeScheduleSerializer, TimeSlotSerializer
|
||||||
|
|
||||||
|
# Create your views here.
|
||||||
|
|
||||||
|
|
||||||
|
class TimeSlotViewSet(viewsets.ModelViewSet):
|
||||||
|
# permission_classes = [IsAuthenticated]
|
||||||
|
serializer_class = TimeSlotSerializer
|
||||||
|
queryset = TimeSlot.objects.all()
|
||||||
|
|
||||||
|
|
||||||
|
class TimeScheduleViewSet(viewsets.ModelViewSet):
|
||||||
|
# permission_classes = [IsAuthenticated]
|
||||||
|
serializer_class = TimeScheduleSerializer
|
||||||
|
queryset = TimeSchedule.objects.all()
|
Loading…
Reference in a new issue