mirror of
https://github.com/lemeow125/InfoTech-Backend.git
synced 2024-11-16 22:19:25 +08:00
Created students app
This commit is contained in:
parent
4c8eb00197
commit
8527870f90
12 changed files with 129 additions and 1 deletions
|
@ -3,5 +3,6 @@ from django.urls import path, include
|
|||
|
||||
urlpatterns = [
|
||||
path('', include('subjects.urls')),
|
||||
path('', include('students.urls')),
|
||||
path('accounts/', include('accounts.urls')),
|
||||
]
|
||||
|
|
|
@ -42,7 +42,8 @@ INSTALLED_APPS = [
|
|||
'rest_framework',
|
||||
'rest_framework.authtoken',
|
||||
'djoser',
|
||||
'subjects'
|
||||
'subjects',
|
||||
'students'
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
|
|
0
infotech/students/__init__.py
Normal file
0
infotech/students/__init__.py
Normal file
3
infotech/students/admin.py
Normal file
3
infotech/students/admin.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
6
infotech/students/apps.py
Normal file
6
infotech/students/apps.py
Normal file
|
@ -0,0 +1,6 @@
|
|||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class StudentsConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'students'
|
35
infotech/students/migrations/0001_initial.py
Normal file
35
infotech/students/migrations/0001_initial.py
Normal file
|
@ -0,0 +1,35 @@
|
|||
# Generated by Django 4.1.7 on 2023-03-21 13:47
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Student',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('first_name', models.CharField(max_length=40)),
|
||||
('middle_name', models.CharField(max_length=40)),
|
||||
('last_name', models.CharField(max_length=40)),
|
||||
('age', models.IntegerField()),
|
||||
('sex', models.CharField(choices=[('M', 'Male'), ('F', 'Female')], max_length=1)),
|
||||
('birthdate', models.DateField()),
|
||||
('address', models.CharField(max_length=150)),
|
||||
('birthplace', models.CharField(max_length=150)),
|
||||
('mother_name', models.CharField(max_length=80)),
|
||||
('father_name', models.CharField(max_length=80)),
|
||||
('registrar_done', models.BooleanField()),
|
||||
('clearance_done', models.BooleanField()),
|
||||
('pta_done', models.BooleanField()),
|
||||
('enrolled_subjects', models.CharField(max_length=800)),
|
||||
('year_level', models.CharField(choices=[('IU-Y1', '1st Year'), ('IU-Y2', '2nd Year'), ('IU-Y3', '3rd Year'), ('IU-Y4', '4th Year')], max_length=20)),
|
||||
],
|
||||
),
|
||||
]
|
0
infotech/students/migrations/__init__.py
Normal file
0
infotech/students/migrations/__init__.py
Normal file
40
infotech/students/models.py
Normal file
40
infotech/students/models.py
Normal file
|
@ -0,0 +1,40 @@
|
|||
from django.db import models
|
||||
from django.contrib.postgres.fields import ArrayField
|
||||
# Create your models here.
|
||||
|
||||
|
||||
class Student(models.Model):
|
||||
|
||||
class YearLevels(models.TextChoices):
|
||||
FIRST_YEAR = 'IU-Y1', '1st Year'
|
||||
SECOND_YEAR = 'IU-Y2', '2nd Year'
|
||||
THIRD_YEAR = 'IU-Y3', '3rd Year'
|
||||
FOURTH_YEAR = 'IU-Y4', '4th Year'
|
||||
|
||||
class SexChoices(models.TextChoices):
|
||||
MALE = 'M', 'Male'
|
||||
FEMALE = 'F', 'Female'
|
||||
|
||||
first_name = models.CharField(max_length=40)
|
||||
middle_name = models.CharField(max_length=40)
|
||||
last_name = models.CharField(max_length=40)
|
||||
#
|
||||
age = models.IntegerField()
|
||||
sex = models.CharField(max_length=1, choices=SexChoices.choices)
|
||||
birthdate = models.DateField()
|
||||
#
|
||||
address = models.CharField(max_length=150)
|
||||
birthplace = models.CharField(max_length=150)
|
||||
#
|
||||
mother_name = models.CharField(max_length=80)
|
||||
father_name = models.CharField(max_length=80)
|
||||
#
|
||||
registrar_done = models.BooleanField()
|
||||
clearance_done = models.BooleanField()
|
||||
pta_done = models.BooleanField()
|
||||
#
|
||||
enrolled_subjects = models.CharField(max_length=800)
|
||||
year_level = models.CharField(max_length=20, choices=YearLevels.choices)
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
17
infotech/students/serializers.py
Normal file
17
infotech/students/serializers.py
Normal file
|
@ -0,0 +1,17 @@
|
|||
from rest_framework import serializers
|
||||
from django.contrib.auth.models import User
|
||||
from .models import Student
|
||||
|
||||
|
||||
class StudentSerializer(serializers.HyperlinkedModelSerializer):
|
||||
|
||||
class Meta:
|
||||
model = Student
|
||||
fields = ['id', 'first_name', 'middle_name', 'last_name',
|
||||
'age', 'sex', 'birthdate',
|
||||
'address', 'birthplace',
|
||||
'mother_name', 'father_name',
|
||||
'registrar_done', 'clearance_done', 'pta_done',
|
||||
'enrolled_subjects', 'year_level'
|
||||
]
|
||||
read_only_fields = ['id']
|
3
infotech/students/tests.py
Normal file
3
infotech/students/tests.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
12
infotech/students/urls.py
Normal file
12
infotech/students/urls.py
Normal 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'students', views.StudentViewSet)
|
||||
|
||||
# Wire up our API using automatic URL routing.
|
||||
# Additionally, we include login URLs for the browsable API.
|
||||
urlpatterns = [
|
||||
path('', include(router.urls)),
|
||||
]
|
10
infotech/students/views.py
Normal file
10
infotech/students/views.py
Normal file
|
@ -0,0 +1,10 @@
|
|||
from rest_framework.permissions import IsAuthenticated
|
||||
from rest_framework import viewsets
|
||||
from .serializers import StudentSerializer
|
||||
from .models import Student
|
||||
|
||||
|
||||
class StudentViewSet(viewsets.ModelViewSet):
|
||||
# permission_classes = [IsAuthenticated]
|
||||
serializer_class = StudentSerializer
|
||||
queryset = Student.objects.all()
|
Loading…
Reference in a new issue