2009-01-15 12:06:34 +01:00
|
|
|
# coding: utf-8
|
2013-02-13 18:37:40 +01:00
|
|
|
from django.contrib.contenttypes import generic
|
|
|
|
from django.contrib.contenttypes.models import ContentType
|
2010-11-22 19:00:01 +01:00
|
|
|
from django.db import models
|
2012-08-12 12:32:08 +02:00
|
|
|
from django.utils.encoding import python_2_unicode_compatible
|
2009-01-15 12:06:34 +01:00
|
|
|
|
2010-08-20 16:28:42 +02:00
|
|
|
|
2012-08-12 12:32:08 +02:00
|
|
|
@python_2_unicode_compatible
|
2009-01-15 12:06:34 +01:00
|
|
|
class Author(models.Model):
|
2009-03-12 12:52:55 +01:00
|
|
|
name = models.CharField(max_length=100)
|
|
|
|
age = models.IntegerField()
|
|
|
|
friends = models.ManyToManyField('self', blank=True)
|
2009-01-15 12:06:34 +01:00
|
|
|
|
2012-08-12 12:32:08 +02:00
|
|
|
def __str__(self):
|
2009-03-12 12:52:55 +01:00
|
|
|
return self.name
|
2009-01-15 12:06:34 +01:00
|
|
|
|
2010-08-20 16:28:42 +02:00
|
|
|
|
2012-08-12 12:32:08 +02:00
|
|
|
@python_2_unicode_compatible
|
2009-01-15 12:06:34 +01:00
|
|
|
class Publisher(models.Model):
|
2009-05-07 20:06:22 +02:00
|
|
|
name = models.CharField(max_length=255)
|
2009-03-12 12:52:55 +01:00
|
|
|
num_awards = models.IntegerField()
|
2009-01-15 12:06:34 +01:00
|
|
|
|
2012-08-12 12:32:08 +02:00
|
|
|
def __str__(self):
|
2009-03-12 12:52:55 +01:00
|
|
|
return self.name
|
2009-01-15 12:06:34 +01:00
|
|
|
|
2010-08-20 16:28:42 +02:00
|
|
|
|
2013-02-19 02:12:37 +01:00
|
|
|
class ItemTag(models.Model):
|
2013-02-13 18:37:40 +01:00
|
|
|
tag = models.CharField(max_length=100)
|
|
|
|
content_type = models.ForeignKey(ContentType)
|
|
|
|
object_id = models.PositiveIntegerField()
|
|
|
|
content_object = generic.GenericForeignKey('content_type', 'object_id')
|
|
|
|
|
|
|
|
|
2012-08-12 12:32:08 +02:00
|
|
|
@python_2_unicode_compatible
|
2009-01-15 12:06:34 +01:00
|
|
|
class Book(models.Model):
|
2009-03-12 12:52:55 +01:00
|
|
|
isbn = models.CharField(max_length=9)
|
2009-05-07 20:06:22 +02:00
|
|
|
name = models.CharField(max_length=255)
|
2009-03-12 12:52:55 +01:00
|
|
|
pages = models.IntegerField()
|
|
|
|
rating = models.FloatField()
|
|
|
|
price = models.DecimalField(decimal_places=2, max_digits=6)
|
|
|
|
authors = models.ManyToManyField(Author)
|
|
|
|
contact = models.ForeignKey(Author, related_name='book_contact_set')
|
|
|
|
publisher = models.ForeignKey(Publisher)
|
|
|
|
pubdate = models.DateField()
|
2013-02-19 02:12:37 +01:00
|
|
|
tags = generic.GenericRelation(ItemTag)
|
2009-03-12 12:52:55 +01:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ('name',)
|
|
|
|
|
2012-08-12 12:32:08 +02:00
|
|
|
def __str__(self):
|
2009-03-12 12:52:55 +01:00
|
|
|
return self.name
|
2009-01-15 12:06:34 +01:00
|
|
|
|
2010-08-20 16:28:42 +02:00
|
|
|
|
2012-08-12 12:32:08 +02:00
|
|
|
@python_2_unicode_compatible
|
2009-01-15 12:06:34 +01:00
|
|
|
class Store(models.Model):
|
2009-05-07 20:06:22 +02:00
|
|
|
name = models.CharField(max_length=255)
|
2009-03-12 12:52:55 +01:00
|
|
|
books = models.ManyToManyField(Book)
|
|
|
|
original_opening = models.DateTimeField()
|
|
|
|
friday_night_closing = models.TimeField()
|
2009-01-15 12:06:34 +01:00
|
|
|
|
2012-08-12 12:32:08 +02:00
|
|
|
def __str__(self):
|
2009-03-12 12:52:55 +01:00
|
|
|
return self.name
|
|
|
|
|
|
|
|
class Entries(models.Model):
|
|
|
|
EntryID = models.AutoField(primary_key=True, db_column='Entry ID')
|
|
|
|
Entry = models.CharField(unique=True, max_length=50)
|
|
|
|
Exclude = models.BooleanField()
|
|
|
|
|
2010-08-20 16:28:42 +02:00
|
|
|
|
2009-03-12 12:52:55 +01:00
|
|
|
class Clues(models.Model):
|
|
|
|
ID = models.AutoField(primary_key=True)
|
|
|
|
EntryID = models.ForeignKey(Entries, verbose_name='Entry', db_column = 'Entry ID')
|
|
|
|
Clue = models.CharField(max_length=150)
|
2009-01-15 12:06:34 +01:00
|
|
|
|
2010-08-20 16:28:42 +02:00
|
|
|
|
2013-02-13 18:37:40 +01:00
|
|
|
class WithManualPK(models.Model):
|
|
|
|
# The generic relations regression test needs two different model
|
|
|
|
# classes with the same PK value, and there are some (external)
|
|
|
|
# DB backends that don't work nicely when assigning integer to AutoField
|
|
|
|
# column (MSSQL at least).
|
|
|
|
id = models.IntegerField(primary_key=True)
|
|
|
|
|
|
|
|
|
2012-08-12 12:32:08 +02:00
|
|
|
@python_2_unicode_compatible
|
2009-04-08 15:19:48 +02:00
|
|
|
class HardbackBook(Book):
|
|
|
|
weight = models.FloatField()
|
|
|
|
|
2012-08-12 12:32:08 +02:00
|
|
|
def __str__(self):
|
2009-04-08 15:19:48 +02:00
|
|
|
return "%s (hardback): %s" % (self.name, self.weight)
|