mirror of
https://github.com/lemeow125/InfoTech-Backend.git
synced 2025-05-16 11:28:14 +08:00
Initial transition to move relationships from subject to schedules
This commit is contained in:
parent
392bf195ae
commit
134df378c3
31 changed files with 334 additions and 22 deletions
0
infotech/professors/__init__.py
Normal file
0
infotech/professors/__init__.py
Normal file
6
infotech/professors/admin.py
Normal file
6
infotech/professors/admin.py
Normal file
|
@ -0,0 +1,6 @@
|
|||
from django.contrib import admin
|
||||
from .models import Professor
|
||||
|
||||
# Register your models here.
|
||||
|
||||
admin.site.register(Professor)
|
6
infotech/professors/apps.py
Normal file
6
infotech/professors/apps.py
Normal file
|
@ -0,0 +1,6 @@
|
|||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class ProfessorsConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'professors'
|
26
infotech/professors/migrations/0001_initial.py
Normal file
26
infotech/professors/migrations/0001_initial.py
Normal file
|
@ -0,0 +1,26 @@
|
|||
# Generated by Django 4.2 on 2023-04-22 01:17
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.utils.timezone
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Professor',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('first_name', models.CharField(max_length=40)),
|
||||
('last_name', models.CharField(max_length=40)),
|
||||
('age', models.IntegerField()),
|
||||
('date_joined', models.DateTimeField(default=django.utils.timezone.now, editable=False)),
|
||||
('gender', models.CharField(choices=[('Male', 'Male'), ('Female', 'Female')], max_length=20)),
|
||||
],
|
||||
),
|
||||
]
|
0
infotech/professors/migrations/__init__.py
Normal file
0
infotech/professors/migrations/__init__.py
Normal file
25
infotech/professors/models.py
Normal file
25
infotech/professors/models.py
Normal file
|
@ -0,0 +1,25 @@
|
|||
from django.db import models
|
||||
from django.utils.timezone import now
|
||||
# Create your models here.
|
||||
|
||||
|
||||
class Professor(models.Model):
|
||||
|
||||
class Genders(models.TextChoices):
|
||||
MALE = 'Male',
|
||||
FEMALE = 'Female',
|
||||
|
||||
first_name = models.CharField(max_length=40)
|
||||
last_name = models.CharField(max_length=40)
|
||||
age = models.IntegerField()
|
||||
date_joined = models.DateTimeField(default=now, editable=False)
|
||||
gender = models.CharField(max_length=20, choices=Genders.choices)
|
||||
# subjects = models.ManyToManyField(
|
||||
# 'subjects.Subject', through='subjects.SubjectProfessor')
|
||||
|
||||
@property
|
||||
def full_name(self):
|
||||
return f"{self.first_name} {self.last_name}"
|
||||
|
||||
def __str__(self):
|
||||
return self.full_name
|
14
infotech/professors/serializers.py
Normal file
14
infotech/professors/serializers.py
Normal file
|
@ -0,0 +1,14 @@
|
|||
from rest_framework import serializers
|
||||
from .models import Professor
|
||||
from subjects.models import Subject
|
||||
|
||||
|
||||
class ProfessorSerializer(serializers.HyperlinkedModelSerializer):
|
||||
date_joined = serializers.DateTimeField(
|
||||
format="%d-%m-%Y %I:%M%p", read_only=True)
|
||||
|
||||
class Meta:
|
||||
model = Professor
|
||||
fields = ('id', 'first_name',
|
||||
'last_name', 'age', 'gender', 'date_joined')
|
||||
read_only_fields = ('id', 'date_joined')
|
3
infotech/professors/tests.py
Normal file
3
infotech/professors/tests.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
13
infotech/professors/urls.py
Normal file
13
infotech/professors/urls.py
Normal file
|
@ -0,0 +1,13 @@
|
|||
from django.urls import include, path
|
||||
from rest_framework import routers
|
||||
from . import views
|
||||
|
||||
router = routers.DefaultRouter()
|
||||
router.register(r'professors', views.ProfessorViewSet)
|
||||
|
||||
# Wire up our API using automatic URL routing.
|
||||
# Additionally, we include login URLs for the browsable API.
|
||||
urlpatterns = [
|
||||
path('', include(router.urls)),
|
||||
|
||||
]
|
10
infotech/professors/views.py
Normal file
10
infotech/professors/views.py
Normal file
|
@ -0,0 +1,10 @@
|
|||
from rest_framework.permissions import IsAuthenticated
|
||||
from rest_framework import viewsets
|
||||
from .serializers import ProfessorSerializer
|
||||
from .models import Professor
|
||||
|
||||
|
||||
class ProfessorViewSet(viewsets.ModelViewSet):
|
||||
# permission_classes = [IsAuthenticated]
|
||||
serializer_class = ProfessorSerializer
|
||||
queryset = Professor.objects.all().order_by('date_joined')
|
Loading…
Add table
Add a link
Reference in a new issue