Added day and timeslots

This commit is contained in:
keannu125 2023-04-22 14:07:08 +08:00
parent 1b02c8f3c6
commit 00c8e6f4f4
17 changed files with 76 additions and 99 deletions

View file

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

View file

@ -47,7 +47,8 @@ INSTALLED_APPS = [
'students',
'professors',
'schedules',
'timeslots',
'daytimes',
]
MIDDLEWARE = [

View file

@ -0,0 +1,5 @@
from django.contrib import admin
from .models import DayTime
# Register your models here.
admin.register(DayTime)

View file

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

View file

@ -0,0 +1,24 @@
# Generated by Django 4.2 on 2023-04-22 06:04
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='DayTime',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.TextField()),
('day', models.TextField(choices=[('Monday', 'Monday'), ('Tuesday', 'Tuesday'), ('Wednesday', 'Wednesday'), ('Thursday', 'Thursday'), ('Friday', 'Friday'), ('Saturday', 'Saturday'), ('Sunday', 'Sunday')])),
('time_start', models.TimeField(max_length=40)),
('time_end', models.TimeField(max_length=20)),
],
),
]

View file

@ -4,20 +4,7 @@ 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 DayTime(models.Model):
class Days(models.TextChoices):
Monday = 'Monday'
Tuesday = 'Tuesday'
@ -29,11 +16,11 @@ class TimeSchedule(models.Model):
name = models.TextField()
day = models.TextField(choices=Days.choices)
time_window = models.ForeignKey(
TimeSlot, on_delete=models.CASCADE)
time_start = models.TimeField(max_length=40)
time_end = models.TimeField(max_length=20)
def save(self, *args, **kwargs):
self.name = f"{self.day} - {self.time_window}"
self.name = f"{self.day} : {self.time_start} - {self.time_end}"
super().save(*args, **kwargs)
def __str__(self):

View file

@ -0,0 +1,10 @@
from rest_framework import serializers
from django.contrib.auth.models import User
from .models import DayTime
class DayTimeSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = DayTime
fields = ('id', 'name', 'day', 'time_start', 'time_end')
read_only_fields = ['id', 'name']

View file

@ -3,8 +3,7 @@ from rest_framework import routers
from . import views
router = routers.DefaultRouter()
router.register(r'timeslots', views.TimeSlotViewSet)
router.register(r'timeschedules', views.TimeScheduleViewSet)
router.register(r'daytimes', views.DayTimeViewSet)
# Wire up our API using automatic URL routing.
# Additionally, we include login URLs for the browsable API.
urlpatterns = [

View file

@ -0,0 +1,11 @@
from rest_framework import viewsets, generics
from .models import DayTime
from .serializers import DayTimeSerializer
# Create your views here.
class DayTimeViewSet(viewsets.ModelViewSet):
# permission_classes = [IsAuthenticated]
serializer_class = DayTimeSerializer
queryset = DayTime.objects.all()

View file

@ -10,6 +10,9 @@ class Schedule(models.Model):
'students.Student', related_name='StudentSchedule_student_assigned', through='schedules.StudentSchedule')
professor = models.OneToOneField(
'professors.Professor', related_name='Professor_full_name', on_delete=models.CASCADE)
# daytimes = models.ForeignKey(
# 'daytimes.DayTime', related_name='DayTime_full_name', on_delete=models.CASCADE)
date_created = models.DateTimeField(default=now, editable=False)
@property
@ -29,3 +32,16 @@ class StudentSchedule(models.Model):
def __str__(self):
return self.schedule
'''
class DayTimeSchedule(models.Model):
schedule = models.ForeignKey(
'schedules.Schedule', on_delete=models.CASCADE)
timeschedule = models.ForeignKey(
'daytimes.DayTime', on_delete=models.CASCADE)
def __str__(self):
return self.schedule
'''

View file

@ -1,6 +0,0 @@
from django.contrib import admin
from .models import TimeSchedule, TimeSlot
# Register your models here.
admin.register(TimeSlot)
admin.register(TimeSchedule)

View file

@ -1,33 +0,0 @@
# 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

@ -1,20 +0,0 @@
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

@ -1,17 +0,0 @@
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()