1 | from django.db import models
|
---|
2 | from django.contrib.auth.models import User
|
---|
3 | from django.contrib.contenttypes import generic
|
---|
4 | from django.contrib.contenttypes.models import ContentType
|
---|
5 |
|
---|
6 |
|
---|
7 | class Pony(models.Model):
|
---|
8 | content_type = models.ForeignKey(ContentType)
|
---|
9 | object_id = models.PositiveIntegerField()
|
---|
10 | content_object = generic.GenericForeignKey()
|
---|
11 | purpleness = models.IntegerField(default=0)
|
---|
12 |
|
---|
13 | class Meta:
|
---|
14 | unique_together = (
|
---|
15 | ('content_type', 'object_id'),
|
---|
16 | )
|
---|
17 |
|
---|
18 | class Person(models.Model):
|
---|
19 | user = models.ForeignKey(User)
|
---|
20 | pony = generic.GenericRelation(Pony)
|
---|