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