add tags to guides

This commit is contained in:
Invinceaman 2020-10-20 17:38:51 -04:00
parent a337a0f468
commit 6aab8f61c4
4 changed files with 55 additions and 25 deletions

View File

@ -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'),
),
]

View File

@ -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'),
),
]

View File

@ -8,7 +8,7 @@ class Subject(models.Model):
url = models.CharField("URL", max_length=20, unique=True, validators=[RegexValidator( url = models.CharField("URL", max_length=20, unique=True, validators=[RegexValidator(
regex="^[a-zA-Z0-9_\-]+$", message="Only alphanumeric, dashes, and underscores allowed")]) 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): def __str__(self):
return self.name return self.name
@ -27,10 +27,15 @@ class Course(models.Model):
class Guide(models.Model): class Guide(models.Model):
id = models.AutoField(primary_key=True) id = models.AutoField(primary_key=True)
name = models.CharField(max_length=100) 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) course = models.ForeignKey(Course, on_delete=models.CASCADE, null=True)
url = models.URLField(max_length=300) url = models.URLField(max_length=300)
def __str__(self): def __str__(self):
return f"[{self.course or 'N/A'}{(', ' + self.teacher) if self.teacher else ''}] {self.name}" 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")])

View File

@ -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'),
),
]