From 6aab8f61c4540968e799a4005e76ef9befca1a13 Mon Sep 17 00:00:00 2001 From: Invinceaman Date: Tue, 20 Oct 2020 17:38:51 -0400 Subject: [PATCH] add tags to guides --- .../migrations/0004_auto_20201015_1929.py | 18 +++++++++++ .../migrations/0005_auto_20201020_1737.py | 30 +++++++++++++++++++ studyguides/apps/courses/models.py | 9 ++++-- .../migrations/0002_auto_20201015_0934.py | 23 -------------- 4 files changed, 55 insertions(+), 25 deletions(-) create mode 100644 studyguides/apps/courses/migrations/0004_auto_20201015_1929.py create mode 100644 studyguides/apps/courses/migrations/0005_auto_20201020_1737.py delete mode 100644 studyguides/studyguides/apps/courses/migrations/0002_auto_20201015_0934.py diff --git a/studyguides/apps/courses/migrations/0004_auto_20201015_1929.py b/studyguides/apps/courses/migrations/0004_auto_20201015_1929.py new file mode 100644 index 0000000..35dbeee --- /dev/null +++ b/studyguides/apps/courses/migrations/0004_auto_20201015_1929.py @@ -0,0 +1,18 @@ +# Generated by Django 3.1.2 on 2020-10-15 23:29 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('courses', '0003_course_url'), + ] + + operations = [ + migrations.AlterField( + model_name='subject', + name='courses', + field=models.ManyToManyField(blank=True, null=True, related_name='subject', to='courses.Course'), + ), + ] diff --git a/studyguides/apps/courses/migrations/0005_auto_20201020_1737.py b/studyguides/apps/courses/migrations/0005_auto_20201020_1737.py new file mode 100644 index 0000000..d97a46f --- /dev/null +++ b/studyguides/apps/courses/migrations/0005_auto_20201020_1737.py @@ -0,0 +1,30 @@ +# Generated by Django 3.1.2 on 2020-10-20 21:37 + +import django.core.validators +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('courses', '0004_auto_20201015_1929'), + ] + + operations = [ + migrations.CreateModel( + name='Tag', + fields=[ + ('id', models.AutoField(primary_key=True, serialize=False)), + ('name', models.SlugField(max_length=100, unique=True, validators=[django.core.validators.RegexValidator(message='Only lowercase alphanumeric, dashes, and underscores allowed', regex='^[a-z0-9_\\-]+$')])), + ], + ), + migrations.RemoveField( + model_name='guide', + name='teacher', + ), + migrations.AddField( + model_name='guide', + name='tags', + field=models.ManyToManyField(null=True, to='courses.Tag'), + ), + ] diff --git a/studyguides/apps/courses/models.py b/studyguides/apps/courses/models.py index eeee663..b9bacc6 100644 --- a/studyguides/apps/courses/models.py +++ b/studyguides/apps/courses/models.py @@ -8,7 +8,7 @@ class Subject(models.Model): url = models.CharField("URL", max_length=20, unique=True, validators=[RegexValidator( regex="^[a-zA-Z0-9_\-]+$", message="Only alphanumeric, dashes, and underscores allowed")]) - courses = models.ManyToManyField("Course", related_name="subject") + courses = models.ManyToManyField("Course", related_name="subject", null=True, blank=True) def __str__(self): return self.name @@ -27,10 +27,15 @@ class Course(models.Model): class Guide(models.Model): id = models.AutoField(primary_key=True) name = models.CharField(max_length=100) - teacher = models.CharField(max_length=100, blank=True) + tags = models.ManyToManyField("Tag", null=True) course = models.ForeignKey(Course, on_delete=models.CASCADE, null=True) url = models.URLField(max_length=300) def __str__(self): return f"[{self.course or 'N/A'}{(', ' + self.teacher) if self.teacher else ''}] {self.name}" + +class Tag(models.Model): + id = models.AutoField(primary_key=True) + name = models.SlugField(max_length=100, unique=True, validators=[RegexValidator( + regex="^[a-z0-9_\-]+$", message="Only lowercase alphanumeric, dashes, and underscores allowed")]) \ No newline at end of file diff --git a/studyguides/studyguides/apps/courses/migrations/0002_auto_20201015_0934.py b/studyguides/studyguides/apps/courses/migrations/0002_auto_20201015_0934.py deleted file mode 100644 index d55fed6..0000000 --- a/studyguides/studyguides/apps/courses/migrations/0002_auto_20201015_0934.py +++ /dev/null @@ -1,23 +0,0 @@ -# Generated by Django 3.1.2 on 2020-10-15 13:34 - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('courses', '0001_initial'), - ] - - operations = [ - migrations.RemoveField( - model_name='course', - name='units', - ), - migrations.AddField( - model_name='guide', - name='course', - field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='courses.course'), - ), - ]