2014-06-07 00:16:17 +08:00
|
|
|
from django.db import models
|
|
|
|
|
|
|
|
|
|
|
|
class Author(models.Model):
|
|
|
|
first_name = models.CharField(max_length=128)
|
|
|
|
last_name = models.CharField(max_length=128)
|
|
|
|
|
|
|
|
|
|
|
|
class Editor(models.Model):
|
|
|
|
name = models.CharField(max_length=128)
|
2015-07-22 22:43:21 +08:00
|
|
|
bestselling_author = models.ForeignKey(Author, models.CASCADE)
|
2014-06-07 00:16:17 +08:00
|
|
|
|
|
|
|
|
|
|
|
class Book(models.Model):
|
|
|
|
title = models.CharField(max_length=128)
|
|
|
|
authors = models.ManyToManyField(Author)
|
2015-07-22 22:43:21 +08:00
|
|
|
editor = models.ForeignKey(Editor, models.CASCADE, related_name="edited_books")
|
2014-06-07 00:16:17 +08:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
default_related_name = "books"
|
|
|
|
|
|
|
|
|
|
|
|
class Store(models.Model):
|
|
|
|
name = models.CharField(max_length=128)
|
|
|
|
address = models.CharField(max_length=128)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
abstract = True
|
|
|
|
default_related_name = "%(app_label)s_%(model_name)ss"
|
|
|
|
|
|
|
|
|
|
|
|
class BookStore(Store):
|
|
|
|
available_books = models.ManyToManyField(Book)
|
|
|
|
|
|
|
|
|
|
|
|
class EditorStore(Store):
|
2015-07-22 22:43:21 +08:00
|
|
|
editor = models.ForeignKey(Editor, models.CASCADE)
|
2014-06-07 00:16:17 +08:00
|
|
|
available_books = models.ManyToManyField(Book)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
default_related_name = "editor_stores"
|