-
Notifications
You must be signed in to change notification settings - Fork 24
/
models.py
39 lines (26 loc) · 985 Bytes
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from django.db import models
from django.urls import reverse
class Publisher(models.Model):
name = models.CharField(null=False, blank=False, max_length=255)
def __str__(self):
return self.name
def get_absolute_url(self):
return reverse("books:publisher_detail", kwargs={"pk": self.pk})
class Book(models.Model):
title = models.CharField(null=False, blank=False, max_length=255)
publisher = models.ForeignKey(
"Publisher",
null=False,
blank=False,
on_delete=models.CASCADE,
related_name="books",
)
def __str__(self):
return self.title
class BookImage(models.Model):
"e.g. image of the cover, backcover, etc."
book = models.ForeignKey(
"Book", null=False, blank=False, on_delete=models.CASCADE, related_name="images"
)
image = models.ImageField(null=False, blank=False, max_length=255)
alt_text = models.CharField(null=False, blank=True, max_length=255)