diff --git a/home/migrations/0007_course_geneds.py b/home/migrations/0007_course_geneds.py new file mode 100644 index 00000000..03602fac --- /dev/null +++ b/home/migrations/0007_course_geneds.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.4 on 2023-02-07 17:50 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('home', '0006_delete_auditlog'), + ] + + operations = [ + migrations.AddField( + model_name='course', + name='geneds', + field=models.JSONField(null=True), + ), + ] diff --git a/home/models.py b/home/models.py index f1c99c0a..5da200a2 100644 --- a/home/models.py +++ b/home/models.py @@ -9,7 +9,7 @@ from django.db.models import (Model, CharField, DateTimeField, TextField, IntegerField, BooleanField, ForeignKey, PositiveIntegerField, EmailField, CASCADE, ManyToManyField, SlugField, TextChoices, FloatField, Manager, - QuerySet, Sum, UniqueConstraint, Index, Count) + QuerySet, Sum, UniqueConstraint, Index, Count, JSONField) from fuzzywuzzy import fuzz @@ -190,7 +190,7 @@ class Course(Model): # indices?). Since recency changes so infrequently, we'll cache it and # update it manually with a custom management command (`updaterecency`). is_recent = BooleanField(default=False) - + geneds = JSONField(null=True) professors = ManyToManyField("Professor", blank=True, through="ProfessorCourse") @@ -219,6 +219,19 @@ def average_gpa(self): def get_absolute_url(self): return reverse("course", kwargs={"name": self.name}) + def gened_str(self): + gened_str = [] + for item in self.geneds: + add_parens = len(item) > 1 and len(self.geneds) > 1 + and_str = "(" if add_parens else "" + and_str += " and ".join(item) + and_str += ")" if add_parens else "" + + # special umdio case. EX: https://api.umd.io/v1/courses/CHEM131 + and_str = and_str.replace("|", " if taken with ") + gened_str.append(and_str) + return " or ".join(gened_str) + def __str__(self): return self.name