Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE
/
django-taggit
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Wiki
Members
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
aa06730d
authored
Apr 05, 2014
by
Florian Apolloner
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'blueyed-deconstruct-keep-non-defaults' into develop
Conflicts: taggit/managers.py
parents
5b25238f
8fb7cfaf
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
1 deletions
+21
-1
taggit/managers.py
+11
-1
tests/tests.py
+10
-0
No files found.
taggit/managers.py
View file @
aa06730d
...
...
@@ -220,12 +220,14 @@ class TaggableManager(RelatedField, Field):
_related_name_counter
=
0
def
__init__
(
self
,
verbose_name
=
_
(
"Tags"
),
help_text
=
_
(
"A comma-separated list of tags."
),
through
=
None
,
blank
=
False
,
related_name
=
None
,
manager
=
_TaggableManager
):
through
=
None
,
blank
=
False
,
related_name
=
None
,
to
=
None
,
manager
=
_TaggableManager
):
Field
.
__init__
(
self
,
verbose_name
=
verbose_name
,
help_text
=
help_text
,
blank
=
blank
,
null
=
True
,
serialize
=
False
)
self
.
through
=
through
or
TaggedItem
self
.
rel
=
TaggableRel
(
self
,
related_name
,
self
.
through
)
self
.
swappable
=
False
self
.
manager
=
manager
# NOTE: `to` is ignored, only used via `deconstruct`.
def
__get__
(
self
,
instance
,
model
):
if
instance
is
not
None
and
instance
.
pk
is
None
:
...
...
@@ -240,9 +242,17 @@ class TaggableManager(RelatedField, Field):
return
manager
def
deconstruct
(
self
):
"""
Deconstruct the object, used with migrations.
"""
name
,
path
,
args
,
kwargs
=
super
(
TaggableManager
,
self
)
.
deconstruct
()
# Remove forced kwargs.
for
kwarg
in
(
'serialize'
,
'null'
):
del
kwargs
[
kwarg
]
# Add arguments related to relations.
# Ref: https://github.com/alex/django-taggit/issues/206#issuecomment-37578676
kwargs
[
'through'
]
=
self
.
through
kwargs
[
'to'
]
=
self
.
through
.
_meta
.
get_field
(
"tag"
)
.
rel
.
to
return
name
,
path
,
args
,
kwargs
def
contribute_to_class
(
self
,
cls
,
name
):
...
...
tests/tests.py
View file @
aa06730d
from
__future__
import
unicode_literals
,
absolute_import
from
unittest
import
TestCase
as
UnitTestCase
from
unittest
import
skipIf
import
django
from
django.conf
import
settings
...
...
@@ -547,3 +548,12 @@ class TagStringParseTestCase(UnitTestCase):
self
.
assertEqual
(
edit_string_for_tags
([
plain
,
spaces
,
comma
]),
'"com,ma", "spa ces", plain'
)
self
.
assertEqual
(
edit_string_for_tags
([
plain
,
comma
]),
'"com,ma", plain'
)
self
.
assertEqual
(
edit_string_for_tags
([
comma
,
spaces
]),
'"com,ma", "spa ces"'
)
@skipIf
(
django
.
VERSION
<
(
1
,
7
),
"not relevant for Django < 1.7"
)
class
DeconstructTestCase
(
UnitTestCase
):
def
test_deconstruct_kwargs_kept
(
self
):
instance
=
TaggableManager
(
through
=
OfficialThroughModel
)
name
,
path
,
args
,
kwargs
=
instance
.
deconstruct
()
new_instance
=
TaggableManager
(
*
args
,
**
kwargs
)
self
.
assertEqual
(
instance
.
rel
.
through
,
new_instance
.
rel
.
through
)
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