Django·Practice drills 11

Drill 26: Compare — Models and migrations

Compare this example with a related lesson or language.

Intermediate 5 min read Lesson 264 of 300 Challenge included
What you will be able to do
  • Compare this example with a related lesson or language.

Practice task

Compare this example with a related lesson or language.

models.pyPython
from django.db import models

class Course(models.Model):
    slug = models.SlugField(unique=True)
    title = models.CharField(max_length=120)
    created_at = models.DateTimeField(auto_now_add=True)

    def __str__(self) -> str:
        return self.title

class Lesson(models.Model):
    course = models.ForeignKey(Course, related_name='lessons', on_delete=models.CASCADE)
    title = models.CharField(max_length=160)
    minutes = models.PositiveSmallIntegerField(default=10)
Your turn

Write your answer

Easy

Compare this example with a related lesson or language.

TEXT · starter
Your answer…
Study tools

Make it yours.

Keep a private note for this lesson, then turn the key ideas into flashcards you can revisit.

Sign in to save notes and flashcards.Both are private to your account and stay with your progress.
Sign in
Finished reading?

Lock in what you just learned.

Mark this lesson complete to save your place and move one step closer to the certificate.

Lesson 264 of 300 · 0% of course