Add teacher field to Guide

This commit is contained in:
Akash Bhave 2020-10-15 14:01:06 -04:00
parent 2fa2c222e9
commit 0820c78b09
No known key found for this signature in database
GPG Key ID: 7293775E03FE1380

View File

@ -2,16 +2,20 @@ from django.db import models
from django.core.validators import RegexValidator, FileExtensionValidator from django.core.validators import RegexValidator, FileExtensionValidator
# Create your models here. # Create your models here.
class Subject(models.Model): class Subject(models.Model):
id = models.AutoField(primary_key=True) id = models.AutoField(primary_key=True)
name = models.CharField(max_length=100, unique=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")]) 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") courses = models.ManyToManyField("Course", related_name="subject")
def __str__(self): def __str__(self):
return self.name return self.name
class Course(models.Model): class Course(models.Model):
id = models.AutoField(primary_key=True) id = models.AutoField(primary_key=True)
name = models.CharField(max_length=100, unique=True) name = models.CharField(max_length=100, unique=True)
@ -19,15 +23,14 @@ class Course(models.Model):
def __str__(self): def __str__(self):
return self.name return self.name
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)
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 self.name return f"[{self.course or 'N/A'}{(', ' + self.teacher) if self.teacher else ''}] {self.name}"