mirror of
https://github.com/lemeow125/StudE-Backend.git
synced 2024-11-17 06:19:24 +08:00
Moved subject course associative entity to subjects app
This commit is contained in:
parent
8d9364274c
commit
ba7e79cdc2
8 changed files with 86 additions and 16 deletions
|
@ -1,6 +1,5 @@
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from .models import Course, SubjectCourse
|
from .models import Course
|
||||||
|
|
||||||
|
|
||||||
admin.site.register(Course)
|
admin.site.register(Course)
|
||||||
admin.site.register(SubjectCourse)
|
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
# Generated by Django 4.2.3 on 2023-07-10 09:34
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('courses', '0002_initial'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='subjectcourse',
|
||||||
|
name='course',
|
||||||
|
),
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='subjectcourse',
|
||||||
|
name='subject',
|
||||||
|
),
|
||||||
|
]
|
|
@ -0,0 +1,22 @@
|
||||||
|
# Generated by Django 4.2.3 on 2023-07-10 09:34
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('subjects', '0002_subjectcourse_alter_subject_courses'),
|
||||||
|
('courses', '0003_remove_subjectcourse_course_and_more'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='course',
|
||||||
|
name='subjects',
|
||||||
|
field=models.ManyToManyField(related_name='SubjectCourse_course', through='subjects.SubjectCourse', to='subjects.subject'),
|
||||||
|
),
|
||||||
|
migrations.DeleteModel(
|
||||||
|
name='SubjectCourse',
|
||||||
|
),
|
||||||
|
]
|
|
@ -8,21 +8,12 @@ class Course(models.Model):
|
||||||
name = models.CharField(max_length=64)
|
name = models.CharField(max_length=64)
|
||||||
shortname = models.CharField(max_length=16)
|
shortname = models.CharField(max_length=16)
|
||||||
subjects = models.ManyToManyField(
|
subjects = models.ManyToManyField(
|
||||||
'subjects.Subject', related_name='SubjectCourse_course', through='courses.SubjectCourse')
|
'subjects.Subject', related_name='SubjectCourse_course', through='subjects.SubjectCourse')
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
|
||||||
class SubjectCourse(models.Model):
|
|
||||||
subject = models.ForeignKey('subjects.Subject', on_delete=models.CASCADE)
|
|
||||||
course = models.ForeignKey(
|
|
||||||
'courses.Course', on_delete=models.CASCADE, null=True)
|
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
return (self.subject + ' under course ' + self.course)
|
|
||||||
|
|
||||||
|
|
||||||
@receiver(post_migrate)
|
@receiver(post_migrate)
|
||||||
def populate_courses(sender, **kwargs):
|
def populate_courses(sender, **kwargs):
|
||||||
if sender.name == 'courses':
|
if sender.name == 'courses':
|
||||||
|
|
|
@ -4,7 +4,7 @@ from rest_framework.exceptions import PermissionDenied
|
||||||
from rest_framework.permissions import IsAuthenticated
|
from rest_framework.permissions import IsAuthenticated
|
||||||
from .serializers import StudyGroupSerializer
|
from .serializers import StudyGroupSerializer
|
||||||
from .models import StudyGroup
|
from .models import StudyGroup
|
||||||
from courses.models import SubjectCourse
|
from subjects.models import SubjectCourse
|
||||||
# Create your views here.
|
# Create your views here.
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from courses.models import Course
|
from .models import Subject, SubjectStudent, SubjectCourse
|
||||||
from .models import Subject, SubjectStudent
|
|
||||||
|
|
||||||
|
|
||||||
class SubjectAdmin(admin.ModelAdmin):
|
class SubjectAdmin(admin.ModelAdmin):
|
||||||
|
@ -9,3 +8,4 @@ class SubjectAdmin(admin.ModelAdmin):
|
||||||
|
|
||||||
admin.site.register(Subject, SubjectAdmin)
|
admin.site.register(Subject, SubjectAdmin)
|
||||||
admin.site.register(SubjectStudent)
|
admin.site.register(SubjectStudent)
|
||||||
|
admin.site.register(SubjectCourse)
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
# Generated by Django 4.2.3 on 2023-07-10 09:34
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('courses', '0003_remove_subjectcourse_course_and_more'),
|
||||||
|
('subjects', '0001_initial'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='SubjectCourse',
|
||||||
|
fields=[
|
||||||
|
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('course', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='courses.course')),
|
||||||
|
('subject', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='subjects.subject')),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='subject',
|
||||||
|
name='courses',
|
||||||
|
field=models.ManyToManyField(related_name='SubjectCourse_subject', through='subjects.SubjectCourse', to='courses.course'),
|
||||||
|
),
|
||||||
|
]
|
|
@ -8,7 +8,7 @@ class Subject(models.Model):
|
||||||
name = models.CharField(max_length=64)
|
name = models.CharField(max_length=64)
|
||||||
code = models.CharField(max_length=16)
|
code = models.CharField(max_length=16)
|
||||||
courses = models.ManyToManyField(
|
courses = models.ManyToManyField(
|
||||||
'courses.Course', through='courses.SubjectCourse', related_name='SubjectCourse_subject')
|
'courses.Course', through='subjects.SubjectCourse', related_name='SubjectCourse_subject')
|
||||||
students = models.ManyToManyField(
|
students = models.ManyToManyField(
|
||||||
'accounts.CustomUser', through='subjects.SubjectStudent', related_name='SubjectStudent_subject')
|
'accounts.CustomUser', through='subjects.SubjectStudent', related_name='SubjectStudent_subject')
|
||||||
|
|
||||||
|
@ -36,3 +36,12 @@ class SubjectStudent(models.Model):
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f'User: User={self.user_id}, Subject={self.subject_name}'
|
return f'User: User={self.user_id}, Subject={self.subject_name}'
|
||||||
|
|
||||||
|
|
||||||
|
class SubjectCourse(models.Model):
|
||||||
|
subject = models.ForeignKey('subjects.Subject', on_delete=models.CASCADE)
|
||||||
|
course = models.ForeignKey(
|
||||||
|
'courses.Course', on_delete=models.CASCADE, null=True)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return (self.subject + ' under course ' + self.course)
|
||||||
|
|
Loading…
Reference in a new issue