2009-12-22 15:18:51 +00:00
|
|
|
from django.conf import settings
|
|
|
|
from django.contrib.auth.models import User
|
|
|
|
from django.contrib.contenttypes.models import ContentType
|
|
|
|
from django.contrib.contenttypes import generic
|
2010-01-22 14:30:06 +00:00
|
|
|
from django.db import models
|
2009-12-22 15:18:51 +00:00
|
|
|
|
|
|
|
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 PersonManager(models.Manager):
|
|
|
|
def get_by_natural_key(self, name):
|
|
|
|
return self.get(name=name)
|
|
|
|
|
|
|
|
class Person(models.Model):
|
|
|
|
objects = PersonManager()
|
|
|
|
name = models.CharField(max_length=100)
|
|
|
|
|
|
|
|
def __unicode__(self):
|
|
|
|
return self.name
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ('name',)
|
|
|
|
|
|
|
|
class Book(models.Model):
|
|
|
|
title = models.CharField(max_length=100)
|
|
|
|
published = models.DateField()
|
|
|
|
authors = models.ManyToManyField(Person)
|
|
|
|
editor = models.ForeignKey(Person, null=True, related_name='edited')
|
|
|
|
reviews = generic.GenericRelation(Review)
|
2010-01-22 14:30:06 +00:00
|
|
|
pages = models.IntegerField(default=100)
|
2009-12-22 15:18:51 +00:00
|
|
|
|
|
|
|
def __unicode__(self):
|
|
|
|
return self.title
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ('title',)
|
|
|
|
|
2010-05-11 13:06:03 +00:00
|
|
|
class Pet(models.Model):
|
|
|
|
name = models.CharField(max_length=100)
|
|
|
|
owner = models.ForeignKey(Person)
|
|
|
|
|
|
|
|
def __unicode__(self):
|
|
|
|
return self.name
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ('name',)
|
|
|
|
|
2009-12-22 15:18:51 +00:00
|
|
|
class UserProfile(models.Model):
|
2010-04-28 04:20:35 +00:00
|
|
|
user = models.OneToOneField(User, null=True)
|
2009-12-22 15:18:51 +00:00
|
|
|
flavor = models.CharField(max_length=100)
|
|
|
|
|
2010-04-28 04:20:35 +00:00
|
|
|
class Meta:
|
|
|
|
ordering = ('flavor',)
|
|
|
|
|