Working on Object Relationships
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
db.sqlite3
BIN
db.sqlite3
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,34 @@
|
||||
# Generated by Django 5.0.6 on 2024-06-18 21:20
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('university', '0003_section_number_of_required_courses'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='agreement',
|
||||
name='sections',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='university',
|
||||
name='agreements',
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='agreement',
|
||||
name='university',
|
||||
field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, to='university.university'),
|
||||
preserve_default=False,
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='section',
|
||||
name='agreement',
|
||||
field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, to='university.agreement'),
|
||||
preserve_default=False,
|
||||
),
|
||||
]
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,25 +1,27 @@
|
||||
from django.db import models
|
||||
from classes.models import Classes
|
||||
|
||||
|
||||
|
||||
# Create your models here.
|
||||
class University(models.Model):
|
||||
name = models.CharField(max_length=200)
|
||||
|
||||
def __str__(self) -> str:
|
||||
return self.name
|
||||
|
||||
class Agreement(models.Model):
|
||||
major = models.CharField(max_length=200)
|
||||
university = models.ForeignKey(University, on_delete=models.CASCADE)
|
||||
|
||||
def __str__(self) -> str:
|
||||
return self.major
|
||||
|
||||
class Section(models.Model):
|
||||
area_name = models.CharField(max_length=200)
|
||||
number_of_required_courses = models.IntegerField()
|
||||
classes = models.ManyToManyField(Classes)
|
||||
agreement = models.ForeignKey(Agreement, on_delete=models.CASCADE)
|
||||
|
||||
def __str__(self) -> str:
|
||||
return self.area_name
|
||||
|
||||
class Agreement(models.Model):
|
||||
major = models.CharField(max_length=200)
|
||||
sections = models.ManyToManyField(Section)
|
||||
|
||||
def __str__(self) -> str:
|
||||
return self.major
|
||||
|
||||
# Create your models here.
|
||||
class University(models.Model):
|
||||
name = models.CharField(max_length=200)
|
||||
agreements = models.ManyToManyField(Agreement)
|
||||
|
||||
def __str__(self) -> str:
|
||||
return self.name
|
||||
return self.area_name
|
||||
@@ -2,28 +2,22 @@ from rest_framework import serializers
|
||||
from .models import University, Agreement, Section
|
||||
|
||||
class UniversitySerializer(serializers.ModelSerializer):
|
||||
|
||||
agreements = serializers.SlugRelatedField(
|
||||
many = True,
|
||||
read_only = True,
|
||||
slug_field="major"
|
||||
)
|
||||
|
||||
|
||||
class Meta:
|
||||
model = University
|
||||
fields = ["name", "agreements"]
|
||||
fields = ["name"]
|
||||
|
||||
class AgreementsSerializer(serializers.ModelSerializer):
|
||||
|
||||
sections = serializers.SlugRelatedField(
|
||||
many = True,
|
||||
read_only = True,
|
||||
slug_field = "area_name"
|
||||
)
|
||||
# sections = serializers.SlugRelatedField(
|
||||
# many = True,
|
||||
# read_only = True,
|
||||
# slug_field = "area_name"
|
||||
# )
|
||||
|
||||
class Meta:
|
||||
model = Agreement
|
||||
fields = ["major", "sections"]
|
||||
fields = ["major", "university"]
|
||||
|
||||
class SectionsSerializer(serializers.ModelSerializer):
|
||||
|
||||
@@ -35,4 +29,4 @@ class SectionsSerializer(serializers.ModelSerializer):
|
||||
|
||||
class Meta:
|
||||
model = Section
|
||||
fields = ["area_name", "number_of_required_courses", "classes"]
|
||||
fields = ["area_name", "number_of_required_courses", "classes", "agreement"]
|
||||
Reference in New Issue
Block a user