diff --git a/stude/courses/admin.py b/stude/courses/admin.py index 83c9d9a..41f0dbf 100644 --- a/stude/courses/admin.py +++ b/stude/courses/admin.py @@ -1,6 +1,5 @@ from django.contrib import admin -from .models import Course, SubjectCourse +from .models import Course admin.site.register(Course) -admin.site.register(SubjectCourse) diff --git a/stude/courses/migrations/0003_remove_subjectcourse_course_and_more.py b/stude/courses/migrations/0003_remove_subjectcourse_course_and_more.py new file mode 100644 index 0000000..f658037 --- /dev/null +++ b/stude/courses/migrations/0003_remove_subjectcourse_course_and_more.py @@ -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', + ), + ] diff --git a/stude/courses/migrations/0004_alter_course_subjects_delete_subjectcourse.py b/stude/courses/migrations/0004_alter_course_subjects_delete_subjectcourse.py new file mode 100644 index 0000000..e01c19b --- /dev/null +++ b/stude/courses/migrations/0004_alter_course_subjects_delete_subjectcourse.py @@ -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', + ), + ] diff --git a/stude/courses/models.py b/stude/courses/models.py index 491a949..a93f22f 100644 --- a/stude/courses/models.py +++ b/stude/courses/models.py @@ -8,21 +8,12 @@ class Course(models.Model): name = models.CharField(max_length=64) shortname = models.CharField(max_length=16) subjects = models.ManyToManyField( - 'subjects.Subject', related_name='SubjectCourse_course', through='courses.SubjectCourse') + 'subjects.Subject', related_name='SubjectCourse_course', through='subjects.SubjectCourse') def __str__(self): 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) def populate_courses(sender, **kwargs): if sender.name == 'courses': diff --git a/stude/study_groups/views.py b/stude/study_groups/views.py index 6c37c9f..6916fd1 100644 --- a/stude/study_groups/views.py +++ b/stude/study_groups/views.py @@ -4,7 +4,7 @@ from rest_framework.exceptions import PermissionDenied from rest_framework.permissions import IsAuthenticated from .serializers import StudyGroupSerializer from .models import StudyGroup -from courses.models import SubjectCourse +from subjects.models import SubjectCourse # Create your views here. diff --git a/stude/subjects/admin.py b/stude/subjects/admin.py index c57f7c0..abe07e7 100644 --- a/stude/subjects/admin.py +++ b/stude/subjects/admin.py @@ -1,6 +1,5 @@ from django.contrib import admin -from courses.models import Course -from .models import Subject, SubjectStudent +from .models import Subject, SubjectStudent, SubjectCourse class SubjectAdmin(admin.ModelAdmin): @@ -9,3 +8,4 @@ class SubjectAdmin(admin.ModelAdmin): admin.site.register(Subject, SubjectAdmin) admin.site.register(SubjectStudent) +admin.site.register(SubjectCourse) diff --git a/stude/subjects/migrations/0002_subjectcourse_alter_subject_courses.py b/stude/subjects/migrations/0002_subjectcourse_alter_subject_courses.py new file mode 100644 index 0000000..2fc3a92 --- /dev/null +++ b/stude/subjects/migrations/0002_subjectcourse_alter_subject_courses.py @@ -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'), + ), + ] diff --git a/stude/subjects/models.py b/stude/subjects/models.py index 5743157..1ffc55d 100644 --- a/stude/subjects/models.py +++ b/stude/subjects/models.py @@ -8,7 +8,7 @@ class Subject(models.Model): name = models.CharField(max_length=64) code = models.CharField(max_length=16) courses = models.ManyToManyField( - 'courses.Course', through='courses.SubjectCourse', related_name='SubjectCourse_subject') + 'courses.Course', through='subjects.SubjectCourse', related_name='SubjectCourse_subject') students = models.ManyToManyField( 'accounts.CustomUser', through='subjects.SubjectStudent', related_name='SubjectStudent_subject') @@ -36,3 +36,12 @@ class SubjectStudent(models.Model): def __str__(self): 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)