2013-12-25 21:13:18 +08:00
|
|
|
from django.db import models
|
|
|
|
|
|
|
|
|
|
|
|
class Author(models.Model):
|
|
|
|
name = models.CharField(max_length=100)
|
|
|
|
age = models.IntegerField()
|
|
|
|
friends = models.ManyToManyField('self', blank=True)
|
|
|
|
|
|
|
|
|
|
|
|
class Publisher(models.Model):
|
|
|
|
name = models.CharField(max_length=255)
|
|
|
|
num_awards = models.IntegerField()
|
|
|
|
|
|
|
|
|
|
|
|
class Book(models.Model):
|
|
|
|
isbn = models.CharField(max_length=9)
|
|
|
|
name = models.CharField(max_length=255)
|
|
|
|
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)
|
2013-12-25 21:13:18 +08:00
|
|
|
pubdate = models.DateField()
|
|
|
|
|
|
|
|
|
|
|
|
class Store(models.Model):
|
|
|
|
name = models.CharField(max_length=255)
|
|
|
|
books = models.ManyToManyField(Book)
|
|
|
|
original_opening = models.DateTimeField()
|
|
|
|
friday_night_closing = models.TimeField()
|
2019-07-10 20:07:48 +08:00
|
|
|
area = models.IntegerField(null=True, db_column='surface')
|
2013-12-25 21:13:18 +08:00
|
|
|
|
|
|
|
|
|
|
|
class DepartmentStore(Store):
|
|
|
|
chain = models.CharField(max_length=255)
|
|
|
|
|
|
|
|
|
|
|
|
class Employee(models.Model):
|
|
|
|
# The order of these fields matter, do not change. Certain backends
|
|
|
|
# rely on field ordering to perform database conversions, and this
|
|
|
|
# model helps to test that.
|
|
|
|
first_name = models.CharField(max_length=20)
|
|
|
|
manager = models.BooleanField(default=False)
|
|
|
|
last_name = models.CharField(max_length=20)
|
2015-07-22 22:43:21 +08:00
|
|
|
store = models.ForeignKey(Store, models.CASCADE)
|
2013-12-25 21:13:18 +08:00
|
|
|
age = models.IntegerField()
|
|
|
|
salary = models.DecimalField(max_digits=8, decimal_places=2)
|
|
|
|
|
|
|
|
|
|
|
|
class Company(models.Model):
|
|
|
|
name = models.CharField(max_length=200)
|
|
|
|
motto = models.CharField(max_length=200, null=True, blank=True)
|
|
|
|
ticker_name = models.CharField(max_length=10, null=True, blank=True)
|
|
|
|
description = models.CharField(max_length=200, null=True, blank=True)
|
|
|
|
|
2015-03-19 11:07:53 +08:00
|
|
|
|
|
|
|
class Ticket(models.Model):
|
|
|
|
active_at = models.DateTimeField()
|
|
|
|
duration = models.DurationField()
|