Chapter 25 · 10 min read
Snippet 4
Snippet 4
Read this model from a course-selling app.
from django.conf import settings
from django.db import models
class Course(models.Model):
title = models.CharField(max_length=100)
teacher = models.ForeignKey(
settings.AUTH_USER_MODEL,
on_delete=models.PROTECT,
related_name="courses",
)
price = models.DecimalField(max_digits=6, decimal_places=2, default=0)
class Meta:
ordering = ["title"]
def __str__(self):
return self.title
