Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
django-rest-framework
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
django-rest-framework
Commits
b73d7e9b
Commit
b73d7e9b
authored
Jan 25, 2013
by
Tom Christie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cleaning up GFK test module. Refs #607.
parent
a3e55215
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
33 deletions
+31
-33
rest_framework/tests/genericrelations.py
+31
-12
rest_framework/tests/models.py
+0
-21
No files found.
rest_framework/tests/genericrelations.py
View file @
b73d7e9b
from
django.contrib.contenttypes.models
import
ContentType
from
django.contrib.contenttypes.generic
import
GenericRelation
,
GenericForeignKey
from
django.db
import
models
from
django.test
import
TestCase
from
django.test
import
TestCase
from
rest_framework
import
serializers
from
rest_framework
import
serializers
from
rest_framework.tests.models
import
*
class
Tag
(
models
.
Model
):
"""
Tags have a descriptive slug, and are attached to an arbitrary object.
"""
tag
=
models
.
SlugField
()
content_type
=
models
.
ForeignKey
(
ContentType
)
object_id
=
models
.
PositiveIntegerField
()
content_object
=
GenericForeignKey
(
'content_type'
,
'object_id'
)
def
__unicode__
(
self
):
return
self
.
tag
class
Bookmark
(
models
.
Model
):
"""
A URL bookmark that may have multiple tags attached.
"""
url
=
models
.
URLField
()
tags
=
GenericRelation
(
Tag
)
class
TestGenericRelations
(
TestCase
):
class
TestGenericRelations
(
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
bookmark
=
Bookmark
(
url
=
'https://www.djangoproject.com/'
)
self
.
bookmark
=
Bookmark
.
objects
.
create
(
url
=
'https://www.djangoproject.com/'
)
bookmark
.
save
()
Tag
.
objects
.
create
(
content_object
=
self
.
bookmark
,
tag
=
'django'
)
django
=
Tag
(
tag_name
=
'django'
)
Tag
.
objects
.
create
(
content_object
=
self
.
bookmark
,
tag
=
'python'
)
django
.
save
()
python
=
Tag
(
tag_name
=
'python'
)
python
.
save
()
t1
=
TaggedItem
(
content_object
=
bookmark
,
tag
=
django
)
t1
.
save
()
t2
=
TaggedItem
(
content_object
=
bookmark
,
tag
=
python
)
t2
.
save
()
self
.
bookmark
=
bookmark
def
test_reverse_generic_relation
(
self
):
def
test_reverse_generic_relation
(
self
):
"""
Test a relationship that spans a GenericRelation field.
"""
class
BookmarkSerializer
(
serializers
.
ModelSerializer
):
class
BookmarkSerializer
(
serializers
.
ModelSerializer
):
tags
=
serializers
.
ManyRelatedField
(
source
=
'tags'
)
tags
=
serializers
.
ManyRelatedField
(
source
=
'tags'
)
...
...
rest_framework/tests/models.py
View file @
b73d7e9b
...
@@ -86,27 +86,6 @@ class ReadOnlyManyToManyModel(RESTFrameworkModel):
...
@@ -86,27 +86,6 @@ class ReadOnlyManyToManyModel(RESTFrameworkModel):
text
=
models
.
CharField
(
max_length
=
100
,
default
=
'anchor'
)
text
=
models
.
CharField
(
max_length
=
100
,
default
=
'anchor'
)
rel
=
models
.
ManyToManyField
(
Anchor
)
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
)
# Model to test filtering.
# Model to test filtering.
class
FilterableItem
(
RESTFrameworkModel
):
class
FilterableItem
(
RESTFrameworkModel
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment