mirror of
https://github.com/django/django.git
synced 2024-11-18 15:34:16 +00:00
87d0a3384c
Thanks jorgecarleitao and mmardini for reviews.
42 lines
1008 B
Python
42 lines
1008 B
Python
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)
|
|
bestselling_author = models.ForeignKey(Author)
|
|
|
|
|
|
class Book(models.Model):
|
|
title = models.CharField(max_length=128)
|
|
authors = models.ManyToManyField(Author)
|
|
editor = models.ForeignKey(Editor, related_name="edited_books")
|
|
|
|
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):
|
|
editor = models.ForeignKey(Editor)
|
|
available_books = models.ManyToManyField(Book)
|
|
|
|
class Meta:
|
|
default_related_name = "editor_stores"
|