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