mirror of
https://github.com/lemeow125/StudE-Backend.git
synced 2024-11-17 06:19:24 +08:00
Improved landmarks view and added prefilled in landmarks
This commit is contained in:
parent
ba7e79cdc2
commit
6e357defcf
5 changed files with 107 additions and 15 deletions
|
@ -1,5 +1,8 @@
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.contrib.gis.db import models as gis_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.
|
# Create your models here.
|
||||||
|
|
||||||
|
|
||||||
|
@ -9,3 +12,24 @@ class Landmark(models.Model):
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
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
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
from rest_framework import generics
|
from rest_framework import generics
|
||||||
from rest_framework.permissions import IsAuthenticated
|
from rest_framework.permissions import IsAuthenticated
|
||||||
from .serializers import LandmarkSerializer
|
from .serializers import LandmarkSerializer
|
||||||
|
from .models import Landmark
|
||||||
|
|
||||||
|
|
||||||
class LandmarkListView(generics.ListAPIView):
|
class LandmarkListView(generics.ListAPIView):
|
||||||
serializer_class = LandmarkSerializer
|
serializer_class = LandmarkSerializer
|
||||||
permission_classes = [IsAuthenticated]
|
# permission_classes = [IsAuthenticated]
|
||||||
|
queryset = Landmark.objects.all()
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from .models import Subject, SubjectStudent, SubjectCourse
|
from .models import Subject, SubjectStudent, SubjectCourse, SubjectSemester, SubjectYearLevel
|
||||||
|
|
||||||
|
|
||||||
class SubjectAdmin(admin.ModelAdmin):
|
class SubjectAdmin(admin.ModelAdmin):
|
||||||
|
@ -9,3 +9,5 @@ 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)
|
admin.site.register(SubjectCourse)
|
||||||
|
admin.site.register(SubjectSemester)
|
||||||
|
admin.site.register(SubjectYearLevel)
|
||||||
|
|
|
@ -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'),
|
||||||
|
),
|
||||||
|
]
|
|
@ -12,17 +12,11 @@ class Subject(models.Model):
|
||||||
students = models.ManyToManyField(
|
students = models.ManyToManyField(
|
||||||
'accounts.CustomUser', through='subjects.SubjectStudent', related_name='SubjectStudent_subject')
|
'accounts.CustomUser', through='subjects.SubjectStudent', related_name='SubjectStudent_subject')
|
||||||
|
|
||||||
year_level = models.ForeignKey(
|
year_level = models.ManyToManyField(
|
||||||
Year_Level,
|
'year_levels.Year_Level', through='subjects.SubjectYearLevel', related_name='SubjectYearLevel_subject')
|
||||||
on_delete=models.SET_NULL,
|
|
||||||
null=True,
|
semester = models.ManyToManyField(
|
||||||
related_name='Year_Level_name'
|
'semesters.Semester', through='subjects.SubjectSemester', related_name='SubjectSemester_subject')
|
||||||
)
|
|
||||||
semester = models.ForeignKey(
|
|
||||||
Semester,
|
|
||||||
on_delete=models.SET_NULL,
|
|
||||||
null=True
|
|
||||||
)
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
@ -35,7 +29,7 @@ class SubjectStudent(models.Model):
|
||||||
'subjects.Subject', on_delete=models.CASCADE)
|
'subjects.Subject', on_delete=models.CASCADE)
|
||||||
|
|
||||||
def __str__(self):
|
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):
|
class SubjectCourse(models.Model):
|
||||||
|
@ -44,4 +38,24 @@ class SubjectCourse(models.Model):
|
||||||
'courses.Course', on_delete=models.CASCADE, null=True)
|
'courses.Course', on_delete=models.CASCADE, null=True)
|
||||||
|
|
||||||
def __str__(self):
|
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}'
|
||||||
|
|
Loading…
Reference in a new issue