Removed associative entity between student and subject

This commit is contained in:
Keannu Bernasol 2023-07-18 15:51:06 +08:00
parent 8a42b58f87
commit e6c4dd7b9c
27 changed files with 82 additions and 264 deletions

View file

@ -5,6 +5,7 @@ from .models import CustomUser
from year_levels.models import Year_Level
from semesters.models import Semester
from courses.models import Course
from subjects.models import Subject
class CustomUserForm(forms.ModelForm):
@ -14,6 +15,8 @@ class CustomUserForm(forms.ModelForm):
queryset=Semester.objects.all(), required=False)
course = forms.ModelChoiceField(
queryset=Course.objects.all(), required=False)
subjects = forms.ModelMultipleChoiceField(
queryset=Subject.objects.all(), required=False)
avatar = forms.ImageField(required=False)
class Meta:
@ -27,7 +30,7 @@ class CustomUserAdmin(UserAdmin):
fieldsets = UserAdmin.fieldsets + (
(None, {'fields': ('student_id_number',
'year_level', 'semester', 'course', 'avatar', 'is_student', 'is_banned')}),
'year_level', 'semester', 'course', 'subjects', 'avatar', 'is_student', 'is_banned')}),
)

View file

@ -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 django.contrib.auth.models

View file

@ -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
import django.db.models.deletion
@ -9,11 +9,11 @@ class Migration(migrations.Migration):
initial = True
dependencies = [
('courses', '0002_initial'),
('auth', '0012_alter_user_first_name_max_length'),
('year_levels', '0001_initial'),
('accounts', '0001_initial'),
('semesters', '0001_initial'),
('year_levels', '0001_initial'),
('auth', '0012_alter_user_first_name_max_length'),
('courses', '0002_initial'),
('subjects', '0001_initial'),
]
@ -36,7 +36,7 @@ class Migration(migrations.Migration):
migrations.AddField(
model_name='customuser',
name='subjects',
field=models.ManyToManyField(related_name='SubjectStudent_user', through='subjects.SubjectStudent', to='subjects.subject'),
field=models.ManyToManyField(to='subjects.subject'),
),
migrations.AddField(
model_name='customuser',

View file

@ -53,8 +53,7 @@ class CustomUser(AbstractUser):
on_delete=models.SET_NULL,
null=True
)
subjects = models.ManyToManyField(
'subjects.Subject', through='subjects.SubjectStudent', related_name='SubjectStudent_user')
subjects = models.ManyToManyField('subjects.Subject')
@property
def full_name(self):
@ -78,3 +77,22 @@ def create_superuser(sender, **kwargs):
# Activate the superuser
superuser.is_active = True
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()

View file

@ -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
import django.db.models.deletion
class Migration(migrations.Migration):
@ -20,11 +19,4 @@ class Migration(migrations.Migration):
('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')),
],
),
]

View file

@ -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
import django.db.models.deletion
class Migration(migrations.Migration):
@ -14,14 +13,9 @@ class Migration(migrations.Migration):
]
operations = [
migrations.AddField(
model_name='subjectcourse',
name='subject',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='subjects.subject'),
),
migrations.AddField(
model_name='course',
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'),
),
]

View file

@ -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',
),
]

View file

@ -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',
),
]

View file

@ -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
from django.db import migrations, models

View file

@ -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

View file

@ -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
import django.contrib.gis.db.models.fields
@ -12,6 +12,7 @@ class Migration(migrations.Migration):
dependencies = [
('accounts', '0002_initial'),
('landmarks', '0001_initial'),
]
operations = [
@ -22,6 +23,7 @@ class Migration(migrations.Migration):
('location', django.contrib.gis.db.models.fields.PointField(blank=True, null=True, srid=4326)),
('active', models.BooleanField(default=False)),
('timestamp', models.DateField(auto_now_add=True)),
('landmark', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='landmarks.landmark')),
],
),
]

View file

@ -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
import django.db.models.deletion
@ -9,8 +9,8 @@ class Migration(migrations.Migration):
initial = True
dependencies = [
('student_status', '0001_initial'),
('study_groups', '0001_initial'),
('student_status', '0001_initial'),
('subjects', '0001_initial'),
]

View file

@ -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'),
),
]

View file

@ -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
from django.db import migrations, models

View file

@ -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.db import migrations, models

View file

@ -1,5 +1,5 @@
from django.contrib import admin
from .models import Subject, SubjectStudent, SubjectCourse, SubjectSemester, SubjectYearLevel
from .models import Subject, SubjectCourse, SubjectSemester, SubjectYearLevel
class SubjectAdmin(admin.ModelAdmin):
@ -7,7 +7,6 @@ class SubjectAdmin(admin.ModelAdmin):
admin.site.register(Subject, SubjectAdmin)
admin.site.register(SubjectStudent)
admin.site.register(SubjectCourse)
admin.site.register(SubjectSemester)
admin.site.register(SubjectYearLevel)

View file

@ -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.db import migrations, models
@ -10,8 +10,8 @@ class Migration(migrations.Migration):
initial = True
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('semesters', '0001_initial'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('courses', '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')),
('name', models.CharField(max_length=64)),
('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(
name='SubjectStudent',
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')),
('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(
model_name='subject',
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(
model_name='subject',
name='year_level',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='Year_Level_name', to='year_levels.year_level'),
name='year_levels',
field=models.ManyToManyField(related_name='SubjectYearLevel_subject', through='subjects.SubjectYearLevel', to='year_levels.year_level'),
),
]

View file

@ -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'),
),
]

View file

@ -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'),
),
]

View file

@ -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',
),
]

View file

@ -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',
),
]

View file

@ -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',
),
]

View file

@ -9,8 +9,7 @@ class Subject(models.Model):
code = models.CharField(max_length=16)
courses = models.ManyToManyField(
'courses.Course', through='subjects.SubjectCourse', related_name='SubjectCourse_subject')
students = models.ManyToManyField(
'accounts.CustomUser', through='subjects.SubjectStudent', related_name='SubjectStudent_subject')
students = models.ManyToManyField('accounts.CustomUser', blank=True)
year_levels = models.ManyToManyField(
'year_levels.Year_Level', through='subjects.SubjectYearLevel', related_name='SubjectYearLevel_subject')
@ -22,16 +21,6 @@ class Subject(models.Model):
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):
subject = models.ForeignKey('subjects.Subject', on_delete=models.CASCADE)
course = models.ForeignKey(

View file

@ -3,9 +3,7 @@ from .models import Subject
from courses.models import Course
from year_levels.models import Year_Level
from semesters.models import Semester
from year_levels.serializers import YearLevelSerializer
from semesters.serializers import SemesterSerializer
from courses.serializers import CourseSerializer
from accounts.models import CustomUser
class SubjectSerializer(serializers.ModelSerializer):

View file

@ -1,7 +1,6 @@
from django.urls import include, path
from .views import SubjectListView
from .views import SubjectByYearSemesterView
from .views import SubjectByYearSemesterView, SubjectListView
from rest_framework import routers
urlpatterns = [
path('', SubjectListView.as_view()),
path('<slug:course_slug>/<slug:year_slug>/<slug:semester_slug>',

View file

@ -1,4 +1,4 @@
from rest_framework import generics
from rest_framework import generics, viewsets
from .models import Subject
from .serializers import SubjectSerializer
from rest_framework.views import APIView

View file

@ -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