2009-01-15 11:06:34 +00:00
|
|
|
# coding: utf-8
|
|
|
|
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-05-28 11:15:36 +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
|
|
|
|
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
|
|
|
|
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)
|
|
|
|
contact = models.ForeignKey(Author, related_name='book_contact_set')
|
|
|
|
publisher = models.ForeignKey(Publisher)
|
|
|
|
pubdate = models.DateField()
|
|
|
|
|
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
|
|
|
|
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
|