2010-10-18 21:34:47 +08:00
|
|
|
from django.db import models
|
2013-12-15 07:15:35 +08:00
|
|
|
from django.db.models import QuerySet
|
|
|
|
from django.db.models.manager import BaseManager
|
2015-12-30 23:51:16 +08:00
|
|
|
from django.urls import reverse
|
2010-10-18 21:34:47 +08:00
|
|
|
|
2011-10-14 05:34:56 +08:00
|
|
|
|
2010-10-18 21:34:47 +08:00
|
|
|
class Artist(models.Model):
|
|
|
|
name = models.CharField(max_length=100)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ["name"]
|
2011-01-03 21:15:58 +08:00
|
|
|
verbose_name = "professional artist"
|
|
|
|
verbose_name_plural = "professional artists"
|
2010-10-18 21:34:47 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2010-10-18 21:34:47 +08:00
|
|
|
return self.name
|
|
|
|
|
|
|
|
def get_absolute_url(self):
|
2012-11-20 20:15:16 +08:00
|
|
|
return reverse("artist_detail", kwargs={"pk": self.id})
|
2010-10-18 21:34:47 +08:00
|
|
|
|
2013-11-03 12:36:09 +08:00
|
|
|
|
2010-10-18 21:34:47 +08:00
|
|
|
class Author(models.Model):
|
|
|
|
name = models.CharField(max_length=100)
|
|
|
|
slug = models.SlugField()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ["name"]
|
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2010-10-18 21:34:47 +08:00
|
|
|
return self.name
|
|
|
|
|
2013-11-03 12:36:09 +08:00
|
|
|
|
2013-12-15 07:15:35 +08:00
|
|
|
class DoesNotExistQuerySet(QuerySet):
|
|
|
|
def get(self, *args, **kwargs):
|
|
|
|
raise Author.DoesNotExist
|
|
|
|
|
2016-11-13 01:11:23 +08:00
|
|
|
|
2013-12-15 07:15:35 +08:00
|
|
|
DoesNotExistBookManager = BaseManager.from_queryset(DoesNotExistQuerySet)
|
|
|
|
|
|
|
|
|
2010-10-18 21:34:47 +08:00
|
|
|
class Book(models.Model):
|
2017-05-10 23:33:46 +08:00
|
|
|
name = models.CharField(max_length=255)
|
2010-10-18 21:34:47 +08:00
|
|
|
slug = models.SlugField()
|
|
|
|
pages = models.IntegerField()
|
|
|
|
authors = models.ManyToManyField(Author)
|
|
|
|
pubdate = models.DateField()
|
|
|
|
|
2013-12-15 07:15:35 +08:00
|
|
|
objects = models.Manager()
|
|
|
|
does_not_exist = DoesNotExistBookManager()
|
|
|
|
|
2010-10-18 21:34:47 +08:00
|
|
|
class Meta:
|
|
|
|
ordering = ["-pubdate"]
|
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2010-10-18 21:34:47 +08:00
|
|
|
return self.name
|
|
|
|
|
2013-11-03 12:36:09 +08:00
|
|
|
|
2010-10-18 21:34:47 +08:00
|
|
|
class Page(models.Model):
|
|
|
|
content = models.TextField()
|
2017-05-10 23:33:46 +08:00
|
|
|
template = models.CharField(max_length=255)
|
2012-05-01 02:41:38 +08:00
|
|
|
|
2013-11-03 12:36:09 +08:00
|
|
|
|
2012-05-01 02:41:38 +08:00
|
|
|
class BookSigning(models.Model):
|
|
|
|
event_date = models.DateTimeField()
|