mirror of
https://github.com/lemeow125/InfoTech-Backend.git
synced 2025-05-16 11:28:14 +08:00
Added day and timeslots
This commit is contained in:
parent
1b02c8f3c6
commit
00c8e6f4f4
17 changed files with 76 additions and 99 deletions
0
infotech/daytimes/__init__.py
Normal file
0
infotech/daytimes/__init__.py
Normal file
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)
|
6
infotech/daytimes/apps.py
Normal file
6
infotech/daytimes/apps.py
Normal file
|
@ -0,0 +1,6 @@
|
|||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class DaytimesConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
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)),
|
||||
],
|
||||
),
|
||||
]
|
0
infotech/daytimes/migrations/__init__.py
Normal file
0
infotech/daytimes/migrations/__init__.py
Normal file
27
infotech/daytimes/models.py
Normal file
27
infotech/daytimes/models.py
Normal file
|
@ -0,0 +1,27 @@
|
|||
from django.db import models
|
||||
from django.core.validators import MaxValueValidator, MinValueValidator
|
||||
from django.utils.timezone import now
|
||||
# Create your models here.
|
||||
|
||||
|
||||
class DayTime(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_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_start} - {self.time_end}"
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
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
infotech/daytimes/tests.py
Normal file
3
infotech/daytimes/tests.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
11
infotech/daytimes/urls.py
Normal file
11
infotech/daytimes/urls.py
Normal file
|
@ -0,0 +1,11 @@
|
|||
from django.urls import include, path
|
||||
from rest_framework import routers
|
||||
from . import views
|
||||
|
||||
router = routers.DefaultRouter()
|
||||
router.register(r'daytimes', views.DayTimeViewSet)
|
||||
# Wire up our API using automatic URL routing.
|
||||
# Additionally, we include login URLs for the browsable API.
|
||||
urlpatterns = [
|
||||
path('', include(router.urls)),
|
||||
]
|
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()
|
Loading…
Add table
Add a link
Reference in a new issue