Add course model

This commit is contained in:
Keannu Bernasol 2023-06-27 14:16:40 +08:00
parent f0d052bc66
commit a12e66caed
12 changed files with 72 additions and 1 deletions

View file

@ -3,5 +3,6 @@ from django.urls import path, include
urlpatterns = [
path('accounts/', include('accounts.urls')),
path('student_status/', include('student_status.urls'))
path('student_status/', include('student_status.urls')),
path('courses/', include('courses.urls'))
]

View file

@ -63,6 +63,7 @@ INSTALLED_APPS = [
'rest_framework.authtoken',
'accounts',
'student_status',
'courses',
]
MIDDLEWARE = [

View file

5
stude/courses/admin.py Normal file
View file

@ -0,0 +1,5 @@
from django.contrib import admin
from .models import Course
admin.site.register(Course)

6
stude/courses/apps.py Normal file
View file

@ -0,0 +1,6 @@
from django.apps import AppConfig
class CoursesConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'courses'

View file

@ -0,0 +1,22 @@
# Generated by Django 4.2.2 on 2023-06-27 05:57
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Course',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('course_name', models.CharField(max_length=64)),
('course_shortname', models.CharField(max_length=16)),
],
),
]

View file

11
stude/courses/models.py Normal file
View file

@ -0,0 +1,11 @@
from django.db import models
from accounts.models import CustomUser as User
# Create your models here.
class Course(models.Model):
course_name = models.CharField(max_length=64)
course_shortname = models.CharField(max_length=16)
def __str__(self):
return self.course_shortname

View file

@ -0,0 +1,8 @@
from rest_framework import serializers
from .models import Course
class CourseSerializer(serializers.ModelSerializer):
class Meta:
model = Course
fields = '__all__'

3
stude/courses/tests.py Normal file
View file

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

6
stude/courses/urls.py Normal file
View file

@ -0,0 +1,6 @@
from django.urls import include, path
from .views import CourseListView
urlpatterns = [
path('', CourseListView.as_view()),
]

8
stude/courses/views.py Normal file
View file

@ -0,0 +1,8 @@
from rest_framework import generics
from .models import Course
from .serializers import CourseSerializer
class CourseListView(generics.ListAPIView):
serializer_class = CourseSerializer
queryset = Course.objects.all()