mirror of
https://github.com/lemeow125/InfoTech-Backend.git
synced 2024-11-17 06:29:26 +08:00
Added day and timeslots
This commit is contained in:
parent
1b02c8f3c6
commit
00c8e6f4f4
17 changed files with 76 additions and 99 deletions
|
@ -6,6 +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('', include('daytimes.urls')),
|
||||||
path('accounts/', include('accounts.urls')),
|
path('accounts/', include('accounts.urls')),
|
||||||
]
|
]
|
||||||
|
|
|
@ -47,7 +47,8 @@ INSTALLED_APPS = [
|
||||||
'students',
|
'students',
|
||||||
'professors',
|
'professors',
|
||||||
'schedules',
|
'schedules',
|
||||||
'timeslots',
|
'daytimes',
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|
||||||
MIDDLEWARE = [
|
MIDDLEWARE = [
|
||||||
|
|
5
infotech/daytimes/admin.py
Normal file
5
infotech/daytimes/admin.py
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
from django.contrib import admin
|
||||||
|
from .models import DayTime
|
||||||
|
|
||||||
|
# Register your models here.
|
||||||
|
admin.register(DayTime)
|
|
@ -1,6 +1,6 @@
|
||||||
from django.apps import AppConfig
|
from django.apps import AppConfig
|
||||||
|
|
||||||
|
|
||||||
class TimeslotsConfig(AppConfig):
|
class DaytimesConfig(AppConfig):
|
||||||
default_auto_field = 'django.db.models.BigAutoField'
|
default_auto_field = 'django.db.models.BigAutoField'
|
||||||
name = 'timeslots'
|
name = 'daytimes'
|
24
infotech/daytimes/migrations/0001_initial.py
Normal file
24
infotech/daytimes/migrations/0001_initial.py
Normal 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)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
]
|
|
@ -4,20 +4,7 @@ from django.utils.timezone import now
|
||||||
# Create your models here.
|
# Create your models here.
|
||||||
|
|
||||||
|
|
||||||
class TimeSlot(models.Model):
|
class DayTime(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):
|
class Days(models.TextChoices):
|
||||||
Monday = 'Monday'
|
Monday = 'Monday'
|
||||||
Tuesday = 'Tuesday'
|
Tuesday = 'Tuesday'
|
||||||
|
@ -29,11 +16,11 @@ class TimeSchedule(models.Model):
|
||||||
|
|
||||||
name = models.TextField()
|
name = models.TextField()
|
||||||
day = models.TextField(choices=Days.choices)
|
day = models.TextField(choices=Days.choices)
|
||||||
time_window = models.ForeignKey(
|
time_start = models.TimeField(max_length=40)
|
||||||
TimeSlot, on_delete=models.CASCADE)
|
time_end = models.TimeField(max_length=20)
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
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)
|
super().save(*args, **kwargs)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
10
infotech/daytimes/serializers.py
Normal file
10
infotech/daytimes/serializers.py
Normal 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']
|
|
@ -3,8 +3,7 @@ from rest_framework import routers
|
||||||
from . import views
|
from . import views
|
||||||
|
|
||||||
router = routers.DefaultRouter()
|
router = routers.DefaultRouter()
|
||||||
router.register(r'timeslots', views.TimeSlotViewSet)
|
router.register(r'daytimes', views.DayTimeViewSet)
|
||||||
router.register(r'timeschedules', views.TimeScheduleViewSet)
|
|
||||||
# Wire up our API using automatic URL routing.
|
# Wire up our API using automatic URL routing.
|
||||||
# Additionally, we include login URLs for the browsable API.
|
# Additionally, we include login URLs for the browsable API.
|
||||||
urlpatterns = [
|
urlpatterns = [
|
11
infotech/daytimes/views.py
Normal file
11
infotech/daytimes/views.py
Normal 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()
|
|
@ -10,6 +10,9 @@ class Schedule(models.Model):
|
||||||
'students.Student', related_name='StudentSchedule_student_assigned', through='schedules.StudentSchedule')
|
'students.Student', related_name='StudentSchedule_student_assigned', through='schedules.StudentSchedule')
|
||||||
professor = models.OneToOneField(
|
professor = models.OneToOneField(
|
||||||
'professors.Professor', related_name='Professor_full_name', on_delete=models.CASCADE)
|
'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)
|
date_created = models.DateTimeField(default=now, editable=False)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -29,3 +32,16 @@ class StudentSchedule(models.Model):
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.schedule
|
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
|
||||||
|
|
||||||
|
'''
|
||||||
|
|
|
@ -1,6 +0,0 @@
|
||||||
from django.contrib import admin
|
|
||||||
from .models import TimeSchedule, TimeSlot
|
|
||||||
|
|
||||||
# Register your models here.
|
|
||||||
admin.register(TimeSlot)
|
|
||||||
admin.register(TimeSchedule)
|
|
|
@ -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')),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -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']
|
|
|
@ -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()
|
|
Loading…
Reference in a new issue