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
A prog2-höz tartozó friss repo anyagok itt elérhetőek:
https://git.iit.bme.hu/
Commit
80016ee6
authored
Dec 21, 2013
by
Florian Apolloner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed #176 -- Disallow multiple TaggableManagers with the same through model.
parent
1f4ffa62
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
4 deletions
+14
-4
taggit/managers.py
+6
-4
tests/models.py
+8
-0
No files found.
taggit/managers.py
View file @
80016ee6
...
...
@@ -130,10 +130,12 @@ class TaggableManager(RelatedField, Field):
tagged_items
=
GenericRelation
(
self
.
through
)
tagged_items
.
contribute_to_class
(
cls
,
'tagged_items'
)
for
rel
in
cls
.
_meta
.
local_many_to_many
:
if
isinstance
(
rel
,
TaggableManager
)
and
rel
.
use_gfk
and
rel
!=
self
:
raise
ValueError
(
'You can only have one TaggableManager per model'
' using generic relations.'
)
for
rel
in
cls
.
_meta
.
local_many_to_many
:
if
rel
==
self
or
not
isinstance
(
rel
,
TaggableManager
):
continue
if
rel
.
through
==
self
.
through
:
raise
ValueError
(
'You can
\'
t have two TaggableManagers with the'
' same through model.'
)
def
save_form_data
(
self
,
instance
,
value
):
getattr
(
instance
,
self
.
name
)
.
set
(
*
value
)
...
...
tests/models.py
View file @
80016ee6
...
...
@@ -21,6 +21,14 @@ class MultipleTags(models.Model):
tags1
=
TaggableManager
(
through
=
Through1
,
related_name
=
'tags1'
)
tags2
=
TaggableManager
(
through
=
Through2
,
related_name
=
'tags2'
)
# Ensure that two TaggableManagers with GFK via different through models are allowed.
class
ThroughGFK
(
GenericTaggedItemBase
):
tag
=
models
.
ForeignKey
(
Tag
,
related_name
=
'tagged_items'
)
class
MultipleTagsGFK
(
models
.
Model
):
tags1
=
TaggableManager
(
related_name
=
'tagsgfk1'
)
tags2
=
TaggableManager
(
through
=
ThroughGFK
,
related_name
=
'tagsgfk2'
)
@python_2_unicode_compatible
class
Food
(
models
.
Model
):
...
...
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