2009-01-15 19:06:34 +08:00
|
|
|
# coding: utf-8
|
2010-11-23 02:00:01 +08:00
|
|
|
from django.db import models
|
2009-01-15 19:06:34 +08:00
|
|
|
|
2010-08-20 22:28:42 +08:00
|
|
|
|
2009-01-15 19:06:34 +08:00
|
|
|
class Author(models.Model):
|
2009-03-12 19:52:55 +08:00
|
|
|
name = models.CharField(max_length=100)
|
|
|
|
age = models.IntegerField()
|
|
|
|
friends = models.ManyToManyField('self', blank=True)
|
2009-01-15 19:06:34 +08:00
|
|
|
|
2009-03-12 19:52:55 +08:00
|
|
|
def __unicode__(self):
|
|
|
|
return self.name
|
2009-01-15 19:06:34 +08:00
|
|
|
|
2010-08-20 22:28:42 +08:00
|
|
|
|
2009-01-15 19:06:34 +08:00
|
|
|
class Publisher(models.Model):
|
2009-05-08 02:06:22 +08:00
|
|
|
name = models.CharField(max_length=255)
|
2009-03-12 19:52:55 +08:00
|
|
|
num_awards = models.IntegerField()
|
2009-01-15 19:06:34 +08:00
|
|
|
|
2009-03-12 19:52:55 +08:00
|
|
|
def __unicode__(self):
|
|
|
|
return self.name
|
2009-01-15 19:06:34 +08:00
|
|
|
|
2010-08-20 22:28:42 +08:00
|
|
|
|
2009-01-15 19:06:34 +08:00
|
|
|
class Book(models.Model):
|
2009-03-12 19:52:55 +08:00
|
|
|
isbn = models.CharField(max_length=9)
|
2009-05-08 02:06:22 +08:00
|
|
|
name = models.CharField(max_length=255)
|
2009-03-12 19:52:55 +08: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()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ('name',)
|
|
|
|
|
|
|
|
def __unicode__(self):
|
|
|
|
return self.name
|
2009-01-15 19:06:34 +08:00
|
|
|
|
2010-08-20 22:28:42 +08:00
|
|
|
|
2009-01-15 19:06:34 +08:00
|
|
|
class Store(models.Model):
|
2009-05-08 02:06:22 +08:00
|
|
|
name = models.CharField(max_length=255)
|
2009-03-12 19:52:55 +08:00
|
|
|
books = models.ManyToManyField(Book)
|
|
|
|
original_opening = models.DateTimeField()
|
|
|
|
friday_night_closing = models.TimeField()
|
2009-01-15 19:06:34 +08:00
|
|
|
|
2009-03-12 19:52:55 +08:00
|
|
|
def __unicode__(self):
|
|
|
|
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 22:28:42 +08:00
|
|
|
|
2009-03-12 19:52:55 +08: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 19:06:34 +08:00
|
|
|
|
2010-08-20 22:28:42 +08:00
|
|
|
|
2009-04-08 21:19:48 +08:00
|
|
|
class HardbackBook(Book):
|
|
|
|
weight = models.FloatField()
|
|
|
|
|
|
|
|
def __unicode__(self):
|
|
|
|
return "%s (hardback): %s" % (self.name, self.weight)
|