Intern — Middle
Migration generation after deploying new models in Django
livecode
Task condition
It is necessary to add two new models to the Django application — PrepLevel and AcademicCourse. The first model will store information about the level of preparation, and the second — about courses, including a code with format validation, a specialty name, and profiles. After creating the models, you should run migrations to reflect the changes in the database.
from django.db import models
from django.core.validators import RegexValidator
# code, specialty, profiles, preparation level
class PrepLevel(models.Model):
level = models.TextField()
class AcademicCourse(models.Model):
code = models.CharField(
max_length=8,
validators=[
RegexValidator(
regex=r'^\d{2}\.\d{2}\.\d{2}$',
message='The string must be in the format "01.03.02".'
)
]
)
speciality = models.TextField()
profs = models.TextField()
level = models.ForeignKey(
PrepLevel,
verbose_name='Preparation level',
on_delete=models.CASCADE,
related_name='courses'
)