mirror of
https://github.com/lemeow125/StudE-Backend.git
synced 2024-11-17 06:19:24 +08:00
Removed associative entity between student and subject
This commit is contained in:
parent
8a42b58f87
commit
e6c4dd7b9c
27 changed files with 82 additions and 264 deletions
|
@ -5,6 +5,7 @@ from .models import CustomUser
|
||||||
from year_levels.models import Year_Level
|
from year_levels.models import Year_Level
|
||||||
from semesters.models import Semester
|
from semesters.models import Semester
|
||||||
from courses.models import Course
|
from courses.models import Course
|
||||||
|
from subjects.models import Subject
|
||||||
|
|
||||||
|
|
||||||
class CustomUserForm(forms.ModelForm):
|
class CustomUserForm(forms.ModelForm):
|
||||||
|
@ -14,6 +15,8 @@ class CustomUserForm(forms.ModelForm):
|
||||||
queryset=Semester.objects.all(), required=False)
|
queryset=Semester.objects.all(), required=False)
|
||||||
course = forms.ModelChoiceField(
|
course = forms.ModelChoiceField(
|
||||||
queryset=Course.objects.all(), required=False)
|
queryset=Course.objects.all(), required=False)
|
||||||
|
subjects = forms.ModelMultipleChoiceField(
|
||||||
|
queryset=Subject.objects.all(), required=False)
|
||||||
avatar = forms.ImageField(required=False)
|
avatar = forms.ImageField(required=False)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
@ -27,7 +30,7 @@ class CustomUserAdmin(UserAdmin):
|
||||||
|
|
||||||
fieldsets = UserAdmin.fieldsets + (
|
fieldsets = UserAdmin.fieldsets + (
|
||||||
(None, {'fields': ('student_id_number',
|
(None, {'fields': ('student_id_number',
|
||||||
'year_level', 'semester', 'course', 'avatar', 'is_student', 'is_banned')}),
|
'year_level', 'semester', 'course', 'subjects', 'avatar', 'is_student', 'is_banned')}),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# Generated by Django 4.2.3 on 2023-07-09 10:57
|
# Generated by Django 4.2.3 on 2023-07-18 07:43
|
||||||
|
|
||||||
import accounts.models
|
import accounts.models
|
||||||
import django.contrib.auth.models
|
import django.contrib.auth.models
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# Generated by Django 4.2.3 on 2023-07-09 10:57
|
# Generated by Django 4.2.3 on 2023-07-18 07:43
|
||||||
|
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
import django.db.models.deletion
|
import django.db.models.deletion
|
||||||
|
@ -9,11 +9,11 @@ class Migration(migrations.Migration):
|
||||||
initial = True
|
initial = True
|
||||||
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
('courses', '0002_initial'),
|
('auth', '0012_alter_user_first_name_max_length'),
|
||||||
|
('year_levels', '0001_initial'),
|
||||||
('accounts', '0001_initial'),
|
('accounts', '0001_initial'),
|
||||||
('semesters', '0001_initial'),
|
('semesters', '0001_initial'),
|
||||||
('year_levels', '0001_initial'),
|
('courses', '0002_initial'),
|
||||||
('auth', '0012_alter_user_first_name_max_length'),
|
|
||||||
('subjects', '0001_initial'),
|
('subjects', '0001_initial'),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ class Migration(migrations.Migration):
|
||||||
migrations.AddField(
|
migrations.AddField(
|
||||||
model_name='customuser',
|
model_name='customuser',
|
||||||
name='subjects',
|
name='subjects',
|
||||||
field=models.ManyToManyField(related_name='SubjectStudent_user', through='subjects.SubjectStudent', to='subjects.subject'),
|
field=models.ManyToManyField(to='subjects.subject'),
|
||||||
),
|
),
|
||||||
migrations.AddField(
|
migrations.AddField(
|
||||||
model_name='customuser',
|
model_name='customuser',
|
||||||
|
|
|
@ -53,8 +53,7 @@ class CustomUser(AbstractUser):
|
||||||
on_delete=models.SET_NULL,
|
on_delete=models.SET_NULL,
|
||||||
null=True
|
null=True
|
||||||
)
|
)
|
||||||
subjects = models.ManyToManyField(
|
subjects = models.ManyToManyField('subjects.Subject')
|
||||||
'subjects.Subject', through='subjects.SubjectStudent', related_name='SubjectStudent_user')
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def full_name(self):
|
def full_name(self):
|
||||||
|
@ -78,3 +77,22 @@ def create_superuser(sender, **kwargs):
|
||||||
# Activate the superuser
|
# Activate the superuser
|
||||||
superuser.is_active = True
|
superuser.is_active = True
|
||||||
superuser.save()
|
superuser.save()
|
||||||
|
|
||||||
|
User = CustomUser
|
||||||
|
username = 'keannu125'
|
||||||
|
email = os.getenv('DJANGO_ADMIN_EMAIL')
|
||||||
|
password = os.getenv('DJANGO_ADMIN_PASSWORD')
|
||||||
|
first_name = 'Keannu'
|
||||||
|
last_name = 'Bernasol'
|
||||||
|
# course = 'Bachelor of Science in Information Technology'
|
||||||
|
# year_level = '1st Year'
|
||||||
|
# semester = '1st Semester'
|
||||||
|
|
||||||
|
if not CustomUser.objects.filter(username=username).exists():
|
||||||
|
# Create the superuser with is_active set to False
|
||||||
|
user = CustomUser.objects.create(
|
||||||
|
username=username, email=email, password=password, first_name=first_name, last_name=last_name)
|
||||||
|
|
||||||
|
# Activate the superuser
|
||||||
|
user.is_active = True
|
||||||
|
user.save()
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
# Generated by Django 4.2.3 on 2023-07-09 10:57
|
# Generated by Django 4.2.3 on 2023-07-18 07:43
|
||||||
|
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
import django.db.models.deletion
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
@ -20,11 +19,4 @@ class Migration(migrations.Migration):
|
||||||
('shortname', models.CharField(max_length=16)),
|
('shortname', models.CharField(max_length=16)),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
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')),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
# Generated by Django 4.2.3 on 2023-07-09 10:57
|
# Generated by Django 4.2.3 on 2023-07-18 07:43
|
||||||
|
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
import django.db.models.deletion
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
@ -14,14 +13,9 @@ class Migration(migrations.Migration):
|
||||||
]
|
]
|
||||||
|
|
||||||
operations = [
|
operations = [
|
||||||
migrations.AddField(
|
|
||||||
model_name='subjectcourse',
|
|
||||||
name='subject',
|
|
||||||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='subjects.subject'),
|
|
||||||
),
|
|
||||||
migrations.AddField(
|
migrations.AddField(
|
||||||
model_name='course',
|
model_name='course',
|
||||||
name='subjects',
|
name='subjects',
|
||||||
field=models.ManyToManyField(related_name='SubjectCourse_course', through='courses.SubjectCourse', to='subjects.subject'),
|
field=models.ManyToManyField(related_name='SubjectCourse_course', through='subjects.SubjectCourse', to='subjects.subject'),
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,21 +0,0 @@
|
||||||
# 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',
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -1,22 +0,0 @@
|
||||||
# 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',
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -1,4 +1,4 @@
|
||||||
# Generated by Django 4.2.3 on 2023-07-10 07:37
|
# Generated by Django 4.2.3 on 2023-07-18 07:43
|
||||||
|
|
||||||
import django.contrib.gis.db.models.fields
|
import django.contrib.gis.db.models.fields
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# Generated by Django 4.2.3 on 2023-07-09 10:57
|
# Generated by Django 4.2.3 on 2023-07-18 07:43
|
||||||
|
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# Generated by Django 4.2.3 on 2023-07-09 10:57
|
# Generated by Django 4.2.3 on 2023-07-18 07:43
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
import django.contrib.gis.db.models.fields
|
import django.contrib.gis.db.models.fields
|
||||||
|
@ -12,6 +12,7 @@ class Migration(migrations.Migration):
|
||||||
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
('accounts', '0002_initial'),
|
('accounts', '0002_initial'),
|
||||||
|
('landmarks', '0001_initial'),
|
||||||
]
|
]
|
||||||
|
|
||||||
operations = [
|
operations = [
|
||||||
|
@ -22,6 +23,7 @@ class Migration(migrations.Migration):
|
||||||
('location', django.contrib.gis.db.models.fields.PointField(blank=True, null=True, srid=4326)),
|
('location', django.contrib.gis.db.models.fields.PointField(blank=True, null=True, srid=4326)),
|
||||||
('active', models.BooleanField(default=False)),
|
('active', models.BooleanField(default=False)),
|
||||||
('timestamp', models.DateField(auto_now_add=True)),
|
('timestamp', models.DateField(auto_now_add=True)),
|
||||||
|
('landmark', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='landmarks.landmark')),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# Generated by Django 4.2.3 on 2023-07-09 10:57
|
# Generated by Django 4.2.3 on 2023-07-18 07:43
|
||||||
|
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
import django.db.models.deletion
|
import django.db.models.deletion
|
||||||
|
@ -9,8 +9,8 @@ class Migration(migrations.Migration):
|
||||||
initial = True
|
initial = True
|
||||||
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
('student_status', '0001_initial'),
|
|
||||||
('study_groups', '0001_initial'),
|
('study_groups', '0001_initial'),
|
||||||
|
('student_status', '0001_initial'),
|
||||||
('subjects', '0001_initial'),
|
('subjects', '0001_initial'),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -1,20 +0,0 @@
|
||||||
# Generated by Django 4.2.3 on 2023-07-14 14:51
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
import django.db.models.deletion
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
('landmarks', '0001_initial'),
|
|
||||||
('student_status', '0002_initial'),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AddField(
|
|
||||||
model_name='studentstatus',
|
|
||||||
name='landmark',
|
|
||||||
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='landmarks.landmark'),
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -1,4 +1,4 @@
|
||||||
# Generated by Django 4.2.3 on 2023-07-09 10:57
|
# Generated by Django 4.2.3 on 2023-07-18 07:43
|
||||||
|
|
||||||
import django.contrib.gis.db.models.fields
|
import django.contrib.gis.db.models.fields
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# Generated by Django 4.2.3 on 2023-07-09 10:57
|
# Generated by Django 4.2.3 on 2023-07-18 07:43
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from .models import Subject, SubjectStudent, SubjectCourse, SubjectSemester, SubjectYearLevel
|
from .models import Subject, SubjectCourse, SubjectSemester, SubjectYearLevel
|
||||||
|
|
||||||
|
|
||||||
class SubjectAdmin(admin.ModelAdmin):
|
class SubjectAdmin(admin.ModelAdmin):
|
||||||
|
@ -7,7 +7,6 @@ class SubjectAdmin(admin.ModelAdmin):
|
||||||
|
|
||||||
|
|
||||||
admin.site.register(Subject, SubjectAdmin)
|
admin.site.register(Subject, SubjectAdmin)
|
||||||
admin.site.register(SubjectStudent)
|
|
||||||
admin.site.register(SubjectCourse)
|
admin.site.register(SubjectCourse)
|
||||||
admin.site.register(SubjectSemester)
|
admin.site.register(SubjectSemester)
|
||||||
admin.site.register(SubjectYearLevel)
|
admin.site.register(SubjectYearLevel)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# Generated by Django 4.2.3 on 2023-07-09 10:57
|
# Generated by Django 4.2.3 on 2023-07-18 07:43
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
|
@ -10,8 +10,8 @@ class Migration(migrations.Migration):
|
||||||
initial = True
|
initial = True
|
||||||
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
|
||||||
('semesters', '0001_initial'),
|
('semesters', '0001_initial'),
|
||||||
|
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||||
('courses', '0001_initial'),
|
('courses', '0001_initial'),
|
||||||
('year_levels', '0001_initial'),
|
('year_levels', '0001_initial'),
|
||||||
]
|
]
|
||||||
|
@ -23,26 +23,50 @@ class Migration(migrations.Migration):
|
||||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
('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(related_name='SubjectCourse_subject', through='courses.SubjectCourse', to='courses.course')),
|
|
||||||
('semester', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='semesters.semester')),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
migrations.CreateModel(
|
migrations.CreateModel(
|
||||||
name='SubjectStudent',
|
name='SubjectYearLevel',
|
||||||
fields=[
|
fields=[
|
||||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
('subject', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='subjects.subject')),
|
('subject', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='subjects.subject')),
|
||||||
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
('year_level', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='year_levels.year_level')),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='SubjectSemester',
|
||||||
|
fields=[
|
||||||
|
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('semester', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='semesters.semester')),
|
||||||
|
('subject', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='subjects.subject')),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
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.AddField(
|
||||||
|
model_name='subject',
|
||||||
|
name='courses',
|
||||||
|
field=models.ManyToManyField(related_name='SubjectCourse_subject', through='subjects.SubjectCourse', to='courses.course'),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='subject',
|
||||||
|
name='semesters',
|
||||||
|
field=models.ManyToManyField(related_name='SubjectSemester_subject', through='subjects.SubjectSemester', to='semesters.semester'),
|
||||||
|
),
|
||||||
migrations.AddField(
|
migrations.AddField(
|
||||||
model_name='subject',
|
model_name='subject',
|
||||||
name='students',
|
name='students',
|
||||||
field=models.ManyToManyField(related_name='SubjectStudent_subject', through='subjects.SubjectStudent', to=settings.AUTH_USER_MODEL),
|
field=models.ManyToManyField(to=settings.AUTH_USER_MODEL),
|
||||||
),
|
),
|
||||||
migrations.AddField(
|
migrations.AddField(
|
||||||
model_name='subject',
|
model_name='subject',
|
||||||
name='year_level',
|
name='year_levels',
|
||||||
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='Year_Level_name', to='year_levels.year_level'),
|
field=models.ManyToManyField(related_name='SubjectYearLevel_subject', through='subjects.SubjectYearLevel', to='year_levels.year_level'),
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,28 +0,0 @@
|
||||||
# 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'),
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -1,50 +0,0 @@
|
||||||
# Generated by Django 4.2.3 on 2023-07-11 06:38
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
import django.db.models.deletion
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
('semesters', '0001_initial'),
|
|
||||||
('year_levels', '0001_initial'),
|
|
||||||
('subjects', '0002_subjectcourse_alter_subject_courses'),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.RemoveField(
|
|
||||||
model_name='subject',
|
|
||||||
name='semester',
|
|
||||||
),
|
|
||||||
migrations.RemoveField(
|
|
||||||
model_name='subject',
|
|
||||||
name='year_level',
|
|
||||||
),
|
|
||||||
migrations.CreateModel(
|
|
||||||
name='SubjectYearLevel',
|
|
||||||
fields=[
|
|
||||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
|
||||||
('subject', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='subjects.subject')),
|
|
||||||
('year_level', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='year_levels.year_level')),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
migrations.CreateModel(
|
|
||||||
name='SubjectSemester',
|
|
||||||
fields=[
|
|
||||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
|
||||||
('semester', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='semesters.semester')),
|
|
||||||
('subject', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='subjects.subject')),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
migrations.AddField(
|
|
||||||
model_name='subject',
|
|
||||||
name='semester',
|
|
||||||
field=models.ManyToManyField(related_name='SubjectSemester_subject', through='subjects.SubjectSemester', to='semesters.semester'),
|
|
||||||
),
|
|
||||||
migrations.AddField(
|
|
||||||
model_name='subject',
|
|
||||||
name='year_level',
|
|
||||||
field=models.ManyToManyField(related_name='SubjectYearLevel_subject', through='subjects.SubjectYearLevel', to='year_levels.year_level'),
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -1,18 +0,0 @@
|
||||||
# Generated by Django 4.2.3 on 2023-07-17 12:43
|
|
||||||
|
|
||||||
from django.db import migrations
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
('subjects', '0003_remove_subject_semester_remove_subject_year_level_and_more'),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.RenameField(
|
|
||||||
model_name='subject',
|
|
||||||
old_name='courses',
|
|
||||||
new_name='course',
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -1,18 +0,0 @@
|
||||||
# Generated by Django 4.2.3 on 2023-07-17 13:11
|
|
||||||
|
|
||||||
from django.db import migrations
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
('subjects', '0004_rename_courses_subject_course'),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.RenameField(
|
|
||||||
model_name='subject',
|
|
||||||
old_name='course',
|
|
||||||
new_name='courses',
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -1,23 +0,0 @@
|
||||||
# Generated by Django 4.2.3 on 2023-07-17 13:16
|
|
||||||
|
|
||||||
from django.db import migrations
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
('subjects', '0005_rename_course_subject_courses'),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.RenameField(
|
|
||||||
model_name='subject',
|
|
||||||
old_name='semester',
|
|
||||||
new_name='semesters',
|
|
||||||
),
|
|
||||||
migrations.RenameField(
|
|
||||||
model_name='subject',
|
|
||||||
old_name='year_level',
|
|
||||||
new_name='year_levels',
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -9,8 +9,7 @@ class Subject(models.Model):
|
||||||
code = models.CharField(max_length=16)
|
code = models.CharField(max_length=16)
|
||||||
courses = models.ManyToManyField(
|
courses = models.ManyToManyField(
|
||||||
'courses.Course', through='subjects.SubjectCourse', related_name='SubjectCourse_subject')
|
'courses.Course', through='subjects.SubjectCourse', related_name='SubjectCourse_subject')
|
||||||
students = models.ManyToManyField(
|
students = models.ManyToManyField('accounts.CustomUser', blank=True)
|
||||||
'accounts.CustomUser', through='subjects.SubjectStudent', related_name='SubjectStudent_subject')
|
|
||||||
|
|
||||||
year_levels = models.ManyToManyField(
|
year_levels = models.ManyToManyField(
|
||||||
'year_levels.Year_Level', through='subjects.SubjectYearLevel', related_name='SubjectYearLevel_subject')
|
'year_levels.Year_Level', through='subjects.SubjectYearLevel', related_name='SubjectYearLevel_subject')
|
||||||
|
@ -22,16 +21,6 @@ class Subject(models.Model):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
|
||||||
class SubjectStudent(models.Model):
|
|
||||||
user = models.ForeignKey(
|
|
||||||
'accounts.CustomUser', on_delete=models.CASCADE)
|
|
||||||
subject = models.ForeignKey(
|
|
||||||
'subjects.Subject', on_delete=models.CASCADE)
|
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
return f'User={self.user.full_name}, Subject={self.subject.name}'
|
|
||||||
|
|
||||||
|
|
||||||
class SubjectCourse(models.Model):
|
class SubjectCourse(models.Model):
|
||||||
subject = models.ForeignKey('subjects.Subject', on_delete=models.CASCADE)
|
subject = models.ForeignKey('subjects.Subject', on_delete=models.CASCADE)
|
||||||
course = models.ForeignKey(
|
course = models.ForeignKey(
|
||||||
|
|
|
@ -3,9 +3,7 @@ from .models import Subject
|
||||||
from courses.models import Course
|
from courses.models import Course
|
||||||
from year_levels.models import Year_Level
|
from year_levels.models import Year_Level
|
||||||
from semesters.models import Semester
|
from semesters.models import Semester
|
||||||
from year_levels.serializers import YearLevelSerializer
|
from accounts.models import CustomUser
|
||||||
from semesters.serializers import SemesterSerializer
|
|
||||||
from courses.serializers import CourseSerializer
|
|
||||||
|
|
||||||
|
|
||||||
class SubjectSerializer(serializers.ModelSerializer):
|
class SubjectSerializer(serializers.ModelSerializer):
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
from django.urls import include, path
|
from django.urls import include, path
|
||||||
from .views import SubjectListView
|
from .views import SubjectByYearSemesterView, SubjectListView
|
||||||
from .views import SubjectByYearSemesterView
|
from rest_framework import routers
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('', SubjectListView.as_view()),
|
path('', SubjectListView.as_view()),
|
||||||
path('<slug:course_slug>/<slug:year_slug>/<slug:semester_slug>',
|
path('<slug:course_slug>/<slug:year_slug>/<slug:semester_slug>',
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from rest_framework import generics
|
from rest_framework import generics, viewsets
|
||||||
from .models import Subject
|
from .models import Subject
|
||||||
from .serializers import SubjectSerializer
|
from .serializers import SubjectSerializer
|
||||||
from rest_framework.views import APIView
|
from rest_framework.views import APIView
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# Generated by Django 4.2.3 on 2023-07-09 10:57
|
# Generated by Django 4.2.3 on 2023-07-18 07:43
|
||||||
|
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue