diff --git a/stude/landmarks/models.py b/stude/landmarks/models.py index f3f2fde..c56f67a 100644 --- a/stude/landmarks/models.py +++ b/stude/landmarks/models.py @@ -1,5 +1,8 @@ from django.db import models from django.contrib.gis.db import models as gis_models +from django.contrib.gis.geos import GEOSGeometry +from django.db.models.signals import post_migrate +from django.dispatch import receiver # Create your models here. @@ -9,3 +12,24 @@ class Landmark(models.Model): def __str__(self): return self.name + + +@receiver(post_migrate) +def populate_courses(sender, **kwargs): + if sender.name == 'landmarks': + SRID = 4326 + Landmark.objects.get_or_create( + name='Gymnasium', + location=GEOSGeometry( + 'POLYGON ((124.656383 8.485963, 124.656576 8.485483, 124.657009 8.485659, 124.656827 8.486126, 124.656383 8.485963))', + srid=4326 + ) + ) + Landmark.objects.get_or_create( + name='Arts & Culture Building', + location=GEOSGeometry( + 'POLYGON ((124.658427 8.486268, 124.658432 8.48617, 124.658582 8.486202, 124.658555 8.4863, 124.658427 8.486268))', + srid=4326 + ) + ) + # Add more predefined records as needed diff --git a/stude/landmarks/views.py b/stude/landmarks/views.py index 084bbf0..9a064f5 100644 --- a/stude/landmarks/views.py +++ b/stude/landmarks/views.py @@ -1,8 +1,10 @@ from rest_framework import generics from rest_framework.permissions import IsAuthenticated from .serializers import LandmarkSerializer +from .models import Landmark class LandmarkListView(generics.ListAPIView): serializer_class = LandmarkSerializer - permission_classes = [IsAuthenticated] + # permission_classes = [IsAuthenticated] + queryset = Landmark.objects.all() diff --git a/stude/subjects/admin.py b/stude/subjects/admin.py index abe07e7..573fffc 100644 --- a/stude/subjects/admin.py +++ b/stude/subjects/admin.py @@ -1,5 +1,5 @@ from django.contrib import admin -from .models import Subject, SubjectStudent, SubjectCourse +from .models import Subject, SubjectStudent, SubjectCourse, SubjectSemester, SubjectYearLevel class SubjectAdmin(admin.ModelAdmin): @@ -9,3 +9,5 @@ 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) diff --git a/stude/subjects/migrations/0003_remove_subject_semester_remove_subject_year_level_and_more.py b/stude/subjects/migrations/0003_remove_subject_semester_remove_subject_year_level_and_more.py new file mode 100644 index 0000000..2224b8b --- /dev/null +++ b/stude/subjects/migrations/0003_remove_subject_semester_remove_subject_year_level_and_more.py @@ -0,0 +1,50 @@ +# 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'), + ), + ] diff --git a/stude/subjects/models.py b/stude/subjects/models.py index 1ffc55d..7b9f611 100644 --- a/stude/subjects/models.py +++ b/stude/subjects/models.py @@ -12,17 +12,11 @@ class Subject(models.Model): students = models.ManyToManyField( 'accounts.CustomUser', through='subjects.SubjectStudent', related_name='SubjectStudent_subject') - year_level = models.ForeignKey( - Year_Level, - on_delete=models.SET_NULL, - null=True, - related_name='Year_Level_name' - ) - semester = models.ForeignKey( - Semester, - on_delete=models.SET_NULL, - null=True - ) + year_level = models.ManyToManyField( + 'year_levels.Year_Level', through='subjects.SubjectYearLevel', related_name='SubjectYearLevel_subject') + + semester = models.ManyToManyField( + 'semesters.Semester', through='subjects.SubjectSemester', related_name='SubjectSemester_subject') def __str__(self): return self.name @@ -35,7 +29,7 @@ class SubjectStudent(models.Model): 'subjects.Subject', on_delete=models.CASCADE) def __str__(self): - return f'User: User={self.user_id}, Subject={self.subject_name}' + return f'User={self.user_id}, Subject={self.subject_name}' class SubjectCourse(models.Model): @@ -44,4 +38,24 @@ class SubjectCourse(models.Model): 'courses.Course', on_delete=models.CASCADE, null=True) def __str__(self): - return (self.subject + ' under course ' + self.course) + return f'Subject={self.subject.name}, Course={self.course.name}' + + +class SubjectYearLevel(models.Model): + subject = models.ForeignKey( + 'subjects.Subject', on_delete=models.CASCADE) + year_level = models.ForeignKey( + 'year_levels.Year_Level', on_delete=models.CASCADE) + + def __str__(self): + return f'Subject={self.subject.name}, Year Level={self.year_level.name}' + + +class SubjectSemester(models.Model): + subject = models.ForeignKey( + 'subjects.Subject', on_delete=models.CASCADE) + semester = models.ForeignKey( + 'semesters.Semester', on_delete=models.CASCADE) + + def __str__(self): + return f'Subject={self.subject.name}, Semester={self.semester.name}'