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
3dbe8804
authored
Feb 13, 2010
by
Alex Gaynor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed #9. COrrectly uniquify slugs.
parent
b4c21524
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
4 deletions
+16
-4
taggit/models.py
+12
-4
taggit/tests/tests.py
+4
-0
No files found.
taggit/models.py
View file @
3dbe8804
from
django.contrib.contenttypes.models
import
ContentType
from
django.contrib.contenttypes.models
import
ContentType
from
django.contrib.contenttypes.generic
import
GenericForeignKey
from
django.contrib.contenttypes.generic
import
GenericForeignKey
from
django.db
import
models
from
django.db
import
models
,
IntegrityError
from
django.template.defaultfilters
import
slugify
from
django.template.defaultfilters
import
slugify
...
@@ -12,9 +12,17 @@ class Tag(models.Model):
...
@@ -12,9 +12,17 @@ class Tag(models.Model):
return
self
.
name
return
self
.
name
def
save
(
self
,
*
args
,
**
kwargs
):
def
save
(
self
,
*
args
,
**
kwargs
):
if
not
self
.
pk
:
if
not
self
.
pk
and
not
self
.
slug
:
self
.
slug
=
slugify
(
self
.
name
)
self
.
slug
=
slug
=
slugify
(
self
.
name
)
super
(
Tag
,
self
)
.
save
(
*
args
,
**
kwargs
)
i
=
0
while
True
:
try
:
return
super
(
Tag
,
self
)
.
save
(
*
args
,
**
kwargs
)
except
IntegrityError
:
i
+=
1
self
.
slug
=
"
%
s_
%
d"
%
(
slug
,
i
)
else
:
return
super
(
Tag
,
self
)
.
save
(
*
args
,
**
kwargs
)
class
TaggedItem
(
models
.
Model
):
class
TaggedItem
(
models
.
Model
):
...
...
taggit/tests/tests.py
View file @
3dbe8804
...
@@ -61,6 +61,10 @@ class AddTagTestCase(BaseTaggingTest):
...
@@ -61,6 +61,10 @@ class AddTagTestCase(BaseTaggingTest):
f
=
Food
()
f
=
Food
()
with
self
.
assert_raises
(
ValueError
):
with
self
.
assert_raises
(
ValueError
):
f
.
tags
.
all
()
f
.
tags
.
all
()
def
test_unique_slug
(
self
):
apple
=
Food
.
objects
.
create
(
name
=
"apple"
)
apple
.
tags
.
add
(
"Red"
,
"red"
)
class
LookupByTagTestCase
(
BaseTaggingTest
):
class
LookupByTagTestCase
(
BaseTaggingTest
):
...
...
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