2009-01-15 19:06:34 +08:00
|
|
|
from django.db import models
|
|
|
|
|
2010-05-28 19:15:36 +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)
|
2020-03-20 02:54:36 +08:00
|
|
|
rating = models.FloatField(null=True)
|
2009-01-15 19:06:34 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2009-03-12 19:52:55 +08:00
|
|
|
return self.name
|
2009-01-15 19:06:34 +08:00
|
|
|
|
2013-11-03 12:36:09 +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()
|
2015-04-24 08:13:24 +08:00
|
|
|
duration = models.DurationField(blank=True, null=True)
|
2009-01-15 19:06:34 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2009-03-12 19:52:55 +08:00
|
|
|
return self.name
|
2009-01-15 19:06:34 +08:00
|
|
|
|
2013-11-03 12:36:09 +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)
|
2015-07-22 22:43:21 +08:00
|
|
|
contact = models.ForeignKey(Author, models.CASCADE, related_name="book_contact_set")
|
|
|
|
publisher = models.ForeignKey(Publisher, models.CASCADE)
|
2009-03-12 19:52:55 +08:00
|
|
|
pubdate = models.DateField()
|
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2009-03-12 19:52:55 +08:00
|
|
|
return self.name
|
2009-01-15 19:06:34 +08:00
|
|
|
|
2013-11-03 12:36:09 +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
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2009-03-12 19:52:55 +08:00
|
|
|
return self.name
|