2014-05-15 17:41:55 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2014-01-22 06:43:33 +00:00
|
|
|
from django.contrib.contenttypes.fields import (
|
2015-01-28 12:35:27 +00:00
|
|
|
GenericForeignKey, GenericRelation,
|
2014-01-22 06:43:33 +00:00
|
|
|
)
|
2013-02-13 17:37:40 +00:00
|
|
|
from django.contrib.contenttypes.models import ContentType
|
2010-11-22 18:00:01 +00:00
|
|
|
from django.db import models
|
2012-08-12 10:32:08 +00:00
|
|
|
from django.utils.encoding import python_2_unicode_compatible
|
2009-01-15 11:06:34 +00:00
|
|
|
|
2010-08-20 14:28:42 +00:00
|
|
|
|
2012-08-12 10:32:08 +00:00
|
|
|
@python_2_unicode_compatible
|
2009-01-15 11:06:34 +00:00
|
|
|
class Author(models.Model):
|
2009-03-12 11:52:55 +00:00
|
|
|
name = models.CharField(max_length=100)
|
|
|
|
age = models.IntegerField()
|
|
|
|
friends = models.ManyToManyField('self', blank=True)
|
2009-01-15 11:06:34 +00:00
|
|
|
|
2012-08-12 10:32:08 +00:00
|
|
|
def __str__(self):
|
2009-03-12 11:52:55 +00:00
|
|
|
return self.name
|
2009-01-15 11:06:34 +00:00
|
|
|
|
2010-08-20 14:28:42 +00:00
|
|
|
|
2012-08-12 10:32:08 +00:00
|
|
|
@python_2_unicode_compatible
|
2009-01-15 11:06:34 +00:00
|
|
|
class Publisher(models.Model):
|
2009-05-07 18:06:22 +00:00
|
|
|
name = models.CharField(max_length=255)
|
2009-03-12 11:52:55 +00:00
|
|
|
num_awards = models.IntegerField()
|
2009-01-15 11:06:34 +00:00
|
|
|
|
2012-08-12 10:32:08 +00:00
|
|
|
def __str__(self):
|
2009-03-12 11:52:55 +00:00
|
|
|
return self.name
|
2009-01-15 11:06:34 +00:00
|
|
|
|
2010-08-20 14:28:42 +00:00
|
|
|
|
2013-02-19 01:12:37 +00:00
|
|
|
class ItemTag(models.Model):
|
2013-02-13 17:37:40 +00:00
|
|
|
tag = models.CharField(max_length=100)
|
2015-07-22 14:43:21 +00:00
|
|
|
content_type = models.ForeignKey(ContentType, models.CASCADE)
|
2013-02-13 17:37:40 +00:00
|
|
|
object_id = models.PositiveIntegerField()
|
2014-01-22 06:43:33 +00:00
|
|
|
content_object = GenericForeignKey('content_type', 'object_id')
|
2013-02-13 17:37:40 +00:00
|
|
|
|
|
|
|
|
2012-08-12 10:32:08 +00:00
|
|
|
@python_2_unicode_compatible
|
2009-01-15 11:06:34 +00:00
|
|
|
class Book(models.Model):
|
2009-03-12 11:52:55 +00:00
|
|
|
isbn = models.CharField(max_length=9)
|
2009-05-07 18:06:22 +00:00
|
|
|
name = models.CharField(max_length=255)
|
2009-03-12 11:52:55 +00:00
|
|
|
pages = models.IntegerField()
|
|
|
|
rating = models.FloatField()
|
|
|
|
price = models.DecimalField(decimal_places=2, max_digits=6)
|
|
|
|
authors = models.ManyToManyField(Author)
|
2015-07-22 14:43:21 +00:00
|
|
|
contact = models.ForeignKey(Author, models.CASCADE, related_name='book_contact_set')
|
|
|
|
publisher = models.ForeignKey(Publisher, models.CASCADE)
|
2009-03-12 11:52:55 +00:00
|
|
|
pubdate = models.DateField()
|
2014-01-22 06:43:33 +00:00
|
|
|
tags = GenericRelation(ItemTag)
|
2009-03-12 11:52:55 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ('name',)
|
|
|
|
|
2012-08-12 10:32:08 +00:00
|
|
|
def __str__(self):
|
2009-03-12 11:52:55 +00:00
|
|
|
return self.name
|
2009-01-15 11:06:34 +00:00
|
|
|
|
2010-08-20 14:28:42 +00:00
|
|
|
|
2012-08-12 10:32:08 +00:00
|
|
|
@python_2_unicode_compatible
|
2009-01-15 11:06:34 +00:00
|
|
|
class Store(models.Model):
|
2009-05-07 18:06:22 +00:00
|
|
|
name = models.CharField(max_length=255)
|
2009-03-12 11:52:55 +00:00
|
|
|
books = models.ManyToManyField(Book)
|
|
|
|
original_opening = models.DateTimeField()
|
|
|
|
friday_night_closing = models.TimeField()
|
2009-01-15 11:06:34 +00:00
|
|
|
|
2012-08-12 10:32:08 +00:00
|
|
|
def __str__(self):
|
2009-03-12 11:52:55 +00:00
|
|
|
return self.name
|
|
|
|
|
2013-11-03 04:36:09 +00:00
|
|
|
|
2009-03-12 11:52:55 +00:00
|
|
|
class Entries(models.Model):
|
|
|
|
EntryID = models.AutoField(primary_key=True, db_column='Entry ID')
|
|
|
|
Entry = models.CharField(unique=True, max_length=50)
|
2013-08-11 20:19:09 +00:00
|
|
|
Exclude = models.BooleanField(default=False)
|
2009-03-12 11:52:55 +00:00
|
|
|
|
2010-08-20 14:28:42 +00:00
|
|
|
|
2009-03-12 11:52:55 +00:00
|
|
|
class Clues(models.Model):
|
|
|
|
ID = models.AutoField(primary_key=True)
|
2015-07-22 14:43:21 +00:00
|
|
|
EntryID = models.ForeignKey(Entries, models.CASCADE, verbose_name='Entry', db_column='Entry ID')
|
2009-03-12 11:52:55 +00:00
|
|
|
Clue = models.CharField(max_length=150)
|
2009-01-15 11:06:34 +00:00
|
|
|
|
2010-08-20 14:28:42 +00:00
|
|
|
|
2013-02-13 17:37:40 +00: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 10:32:08 +00:00
|
|
|
@python_2_unicode_compatible
|
2009-04-08 13:19:48 +00:00
|
|
|
class HardbackBook(Book):
|
|
|
|
weight = models.FloatField()
|
|
|
|
|
2012-08-12 10:32:08 +00:00
|
|
|
def __str__(self):
|
2009-04-08 13:19:48 +00:00
|
|
|
return "%s (hardback): %s" % (self.name, self.weight)
|
2013-09-24 15:23:02 +00:00
|
|
|
|
2013-11-03 04:36:09 +00:00
|
|
|
|
2013-09-24 15:23:02 +00:00
|
|
|
# Models for ticket #21150
|
|
|
|
class Alfa(models.Model):
|
2013-09-24 16:37:55 +00:00
|
|
|
name = models.CharField(max_length=10, null=True)
|
2013-09-24 15:23:02 +00:00
|
|
|
|
2013-11-03 04:36:09 +00:00
|
|
|
|
2013-09-24 15:23:02 +00:00
|
|
|
class Bravo(models.Model):
|
|
|
|
pass
|
|
|
|
|
2013-11-03 04:36:09 +00:00
|
|
|
|
2013-09-24 15:23:02 +00:00
|
|
|
class Charlie(models.Model):
|
2015-07-22 14:43:21 +00:00
|
|
|
alfa = models.ForeignKey(Alfa, models.SET_NULL, null=True)
|
|
|
|
bravo = models.ForeignKey(Bravo, models.SET_NULL, null=True)
|
2015-05-05 11:44:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
class SelfRefFK(models.Model):
|
|
|
|
name = models.CharField(max_length=50)
|
2015-07-22 14:43:21 +00:00
|
|
|
parent = models.ForeignKey('self', models.SET_NULL, null=True, blank=True, related_name='children')
|