Added time schedule model

This commit is contained in:
keannu125 2023-04-22 13:42:09 +08:00
parent 864643278c
commit 1b02c8f3c6
20 changed files with 193 additions and 21 deletions

View file

@ -6,5 +6,6 @@ urlpatterns = [
path('', include('students.urls')),
path('', include('professors.urls')),
path('', include('schedules.urls')),
path('', include('timeslots.urls')),
path('accounts/', include('accounts.urls')),
]

View file

@ -47,6 +47,7 @@ INSTALLED_APPS = [
'students',
'professors',
'schedules',
'timeslots',
]
MIDDLEWARE = [
@ -156,3 +157,5 @@ EMAIL_PORT = '2525'
CORS_ALLOW_ALL_ORIGINS = True
CORS_ALLOW_CREDENTIALS = True
TIME_INPUT_FORMATS = ['%I:%M %p',]

View file

@ -26,3 +26,6 @@ class StudentSchedule(models.Model):
student_assigned = models.ForeignKey(
'students.Student', on_delete=models.CASCADE)
date_joined = models.DateTimeField(default=now, editable=False)
def __str__(self):
return self.schedule

View file

@ -23,13 +23,3 @@ class ScheduleSerializer(serializers.HyperlinkedModelSerializer):
fields = ('id', 'subject', 'students_assigned',
'professor', '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')

View file

@ -9,5 +9,4 @@ router.register(r'schedules', views.ScheduleViewSet)
# Additionally, we include login URLs for the browsable API.
urlpatterns = [
path('', include(router.urls)),
]

View file

@ -3,7 +3,7 @@ from django.shortcuts import render
# Create your views here.
from rest_framework.permissions import IsAuthenticated
from rest_framework import viewsets
from .serializers import ScheduleSerializer, StudentScheduleSerializer
from .serializers import ScheduleSerializer
from .models import Schedule, StudentSchedule
@ -11,9 +11,3 @@ class ScheduleViewSet(viewsets.ModelViewSet):
# permission_classes = [IsAuthenticated]
serializer_class = ScheduleSerializer
queryset = Schedule.objects.all()
class StudentScheduleViewSet(viewsets.ModelViewSet):
# permission_classes = [IsAuthenticated]
serializer_class = StudentScheduleSerializer
queryset = StudentSchedule.objects.all()

View file

@ -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),
),
]

View 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'),
),
]

View file

@ -37,8 +37,9 @@ class Student(models.Model):
clearance_done = models.BooleanField()
pta_done = models.BooleanField()
#
# schedules = models.ManyToManyField(
# 'schedules.Schedule', related_name='StudentSchedule_subject', through='schedules.StudentSchedule')
schedules = models.ManyToManyField(
'schedules.Schedule', related_name='StudentSchedule_subject', through='schedules.StudentSchedule')
#
year_level = models.CharField(max_length=20, choices=YearLevels.choices)
current_semester = models.CharField(
max_length=20, choices=Semesters.choices, default=Semesters.FIRST_SEM)

View file

@ -5,6 +5,8 @@ from schedules.models import Schedule
class StudentSerializer(serializers.HyperlinkedModelSerializer):
schedules = serializers.SlugRelatedField(
queryset=Schedule.objects.all(), slug_field='schedule_subject', allow_null=True)
class Meta:
model = Student
@ -13,6 +15,6 @@ class StudentSerializer(serializers.HyperlinkedModelSerializer):
'address', 'birthplace',
'mother_name', 'father_name',
'registrar_done', 'clearance_done', 'pta_done',
'year_level', 'current_semester'
'schedules', 'year_level', 'current_semester'
]
read_only_fields = ['id', 'full_name']

View file

View 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)

View file

@ -0,0 +1,6 @@
from django.apps import AppConfig
class TimeslotsConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'timeslots'

View 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')),
],
),
]

View 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

View 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']

View file

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

View 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)),
]

View 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()