From 693892ed0104b8ce8cd801e7bec6107feeb88782 Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Thu, 4 Oct 2012 22:07:24 +0100 Subject: Fix for field to make it easier to access field relationships --- rest_framework/tests/models.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'rest_framework/tests/models.py') diff --git a/rest_framework/tests/models.py b/rest_framework/tests/models.py index 969c8297..7c7f485b 100644 --- a/rest_framework/tests/models.py +++ b/rest_framework/tests/models.py @@ -1,4 +1,7 @@ from django.db import models +from django.contrib.contenttypes.models import ContentType +from django.contrib.contenttypes.generic import GenericForeignKey, GenericRelation + # from django.contrib.auth.models import Group @@ -59,3 +62,24 @@ class CallableDefaultValueModel(RESTFrameworkModel): class ManyToManyModel(RESTFrameworkModel): rel = models.ManyToManyField(Anchor) + +# Models to test generic relations + + +class Tag(RESTFrameworkModel): + tag_name = models.SlugField() + + +class TaggedItem(RESTFrameworkModel): + tag = models.ForeignKey(Tag, related_name='items') + content_type = models.ForeignKey(ContentType) + object_id = models.PositiveIntegerField() + content_object = GenericForeignKey('content_type', 'object_id') + + def __unicode__(self): + return self.tag.tag_name + + +class Bookmark(RESTFrameworkModel): + url = models.URLField() + tags = GenericRelation(TaggedItem) -- cgit v1.2.3