From 0820c78b09463f8b3203f64bfb9f78d2d8853041 Mon Sep 17 00:00:00 2001 From: Akash Bhave Date: Thu, 15 Oct 2020 14:01:06 -0400 Subject: [PATCH] Add teacher field to Guide --- studyguides/apps/courses/models.py | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/studyguides/apps/courses/models.py b/studyguides/apps/courses/models.py index fef3f98..d94f3e0 100644 --- a/studyguides/apps/courses/models.py +++ b/studyguides/apps/courses/models.py @@ -2,32 +2,35 @@ from django.db import models from django.core.validators import RegexValidator, FileExtensionValidator # Create your models here. + + class Subject(models.Model): - id = models.AutoField(primary_key = True) - name = models.CharField(max_length=100, unique = True) - url = models.CharField(max_length=20, unique = True, validators=[RegexValidator(regex="^[a-zA-Z0-9_\-]+$", message="Only alphanumeric, dashes, and underscores allowed")]) + id = models.AutoField(primary_key=True) + name = models.CharField(max_length=100, unique=True) + url = models.CharField(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") def __str__(self): return self.name + class Course(models.Model): - id = models.AutoField(primary_key = True) - name = models.CharField(max_length=100, unique = True) + id = models.AutoField(primary_key=True) + name = models.CharField(max_length=100, unique=True) def __str__(self): return self.name + class Guide(models.Model): - id = models.AutoField(primary_key = True) + id = models.AutoField(primary_key=True) name = models.CharField(max_length=100) - + teacher = models.CharField(max_length=100, blank=True) + course = models.ForeignKey(Course, on_delete=models.CASCADE, null=True) url = models.URLField(max_length=300) def __str__(self): - return self.name - - - + return f"[{self.course or 'N/A'}{(', ' + self.teacher) if self.teacher else ''}] {self.name}"