mirror of
https://github.com/django/django.git
synced 2025-10-22 05:09:39 +00:00
git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2009/multidb@11889 bcc190cf-cafb-0310-a4f2-bffc1f526a37
39 lines
1.0 KiB
Python
39 lines
1.0 KiB
Python
from django.conf import settings
|
|
from django.contrib.contenttypes.models import ContentType
|
|
from django.contrib.contenttypes import generic
|
|
from django.db import models, DEFAULT_DB_ALIAS
|
|
|
|
class Review(models.Model):
|
|
source = models.CharField(max_length=100)
|
|
content_type = models.ForeignKey(ContentType)
|
|
object_id = models.PositiveIntegerField()
|
|
content_object = generic.GenericForeignKey()
|
|
|
|
def __unicode__(self):
|
|
return self.source
|
|
|
|
class Meta:
|
|
ordering = ('source',)
|
|
|
|
class Book(models.Model):
|
|
title = models.CharField(max_length=100)
|
|
published = models.DateField()
|
|
authors = models.ManyToManyField('Author')
|
|
reviews = generic.GenericRelation(Review)
|
|
|
|
def __unicode__(self):
|
|
return self.title
|
|
|
|
class Meta:
|
|
ordering = ('title',)
|
|
|
|
class Author(models.Model):
|
|
name = models.CharField(max_length=100)
|
|
favourite_book = models.ForeignKey(Book, null=True, related_name='favourite_of')
|
|
|
|
def __unicode__(self):
|
|
return self.name
|
|
|
|
class Meta:
|
|
ordering = ('name',)
|