mirror of
https://github.com/tjsga/studyguides.git
synced 2025-04-05 11:50:16 -04:00
Add teacher field to Guide
This commit is contained in:
parent
2fa2c222e9
commit
0820c78b09
|
@ -2,32 +2,35 @@ 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)
|
||||||
|
|
||||||
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}"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user