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
73e5b7e4
Commit
73e5b7e4
authored
Jan 30, 2014
by
Xavier Ordoquy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed the object representation in order to pass the tests.
parent
c2ee5223
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
3 deletions
+25
-3
rest_framework/tests/test_genericrelations.py
+25
-3
No files found.
rest_framework/tests/test_genericrelations.py
View file @
73e5b7e4
...
@@ -5,7 +5,27 @@ from django.db import models
...
@@ -5,7 +5,27 @@ 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
try
:
from
django.utils.encoding
import
python_2_unicode_compatible
except
ImportError
:
def
python_2_unicode_compatible
(
klass
):
"""
A decorator that defines __unicode__ and __str__ methods under Python 2.
Under Python 3 it does nothing.
To support Python 2 and 3 with a single code base, define a __str__ method
returning text and apply this decorator to the class.
"""
if
'__str__'
not
in
klass
.
__dict__
:
raise
ValueError
(
"@python_2_unicode_compatible cannot be applied "
"to
%
s because it doesn't define __str__()."
%
klass
.
__name__
)
klass
.
__unicode__
=
klass
.
__str__
klass
.
__str__
=
lambda
self
:
self
.
__unicode__
()
.
encode
(
'utf-8'
)
return
klass
@python_2_unicode_compatible
class
Tag
(
models
.
Model
):
class
Tag
(
models
.
Model
):
"""
"""
Tags have a descriptive slug, and are attached to an arbitrary object.
Tags have a descriptive slug, and are attached to an arbitrary object.
...
@@ -15,10 +35,11 @@ class Tag(models.Model):
...
@@ -15,10 +35,11 @@ class Tag(models.Model):
object_id
=
models
.
PositiveIntegerField
()
object_id
=
models
.
PositiveIntegerField
()
tagged_item
=
GenericForeignKey
(
'content_type'
,
'object_id'
)
tagged_item
=
GenericForeignKey
(
'content_type'
,
'object_id'
)
def
__
unicode
__
(
self
):
def
__
str
__
(
self
):
return
self
.
tag
return
self
.
tag
@python_2_unicode_compatible
class
Bookmark
(
models
.
Model
):
class
Bookmark
(
models
.
Model
):
"""
"""
A URL bookmark that may have multiple tags attached.
A URL bookmark that may have multiple tags attached.
...
@@ -26,10 +47,11 @@ class Bookmark(models.Model):
...
@@ -26,10 +47,11 @@ class Bookmark(models.Model):
url
=
models
.
URLField
()
url
=
models
.
URLField
()
tags
=
GenericRelation
(
Tag
)
tags
=
GenericRelation
(
Tag
)
def
__
unicode
__
(
self
):
def
__
str
__
(
self
):
return
'Bookmark:
%
s'
%
self
.
url
return
'Bookmark:
%
s'
%
self
.
url
@python_2_unicode_compatible
class
Note
(
models
.
Model
):
class
Note
(
models
.
Model
):
"""
"""
A textual note that may have multiple tags attached.
A textual note that may have multiple tags attached.
...
@@ -37,7 +59,7 @@ class Note(models.Model):
...
@@ -37,7 +59,7 @@ class Note(models.Model):
text
=
models
.
TextField
()
text
=
models
.
TextField
()
tags
=
GenericRelation
(
Tag
)
tags
=
GenericRelation
(
Tag
)
def
__
unicode
__
(
self
):
def
__
str
__
(
self
):
return
'Note:
%
s'
%
self
.
text
return
'Note:
%
s'
%
self
.
text
...
...
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