Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
I
internewshid
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
aptivate
client-projects
internewshid
Commits
9e5cffae
Commit
9e5cffae
authored
9 years ago
by
Mark Skipper
Browse files
Options
Downloads
Patches
Plain Diff
WIP refactor to use Term.objects.by_taxonomy
parent
dff22816
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
django/website/taxonomies/models.py
+20
-0
20 additions, 0 deletions
django/website/taxonomies/models.py
django/website/taxonomies/tests/term_tests.py
+8
-0
8 additions, 0 deletions
django/website/taxonomies/tests/term_tests.py
with
28 additions
and
0 deletions
django/website/taxonomies/models.py
+
20
−
0
View file @
9e5cffae
...
...
@@ -50,6 +50,23 @@ class Taxonomy(models.Model):
# to do free tagging use 'multiple' and 'open'
class
TermManager
(
models
.
Manager
):
def
by_taxonomy
(
self
,
taxonomy
,
term_name
):
"""
Fetch an existing Term by its name and its
Taxonomy slug which, together should be unique.
"""
if
isinstance
(
taxonomy
,
basestring
):
taxonomy_slug
=
taxonomy
elif
isinstance
(
taxonomy
,
Taxonomy
):
taxonomy_slug
=
taxonomy
.
slug
else
:
raise
ValueError
(
"
taxonomy must be a Taxonomy instance
"
"
or a valid taxonomy slug
"
)
return
self
.
get
(
taxonomy__slug
=
taxonomy_slug
,
name
=
term_name
)
class
Term
(
models
.
Model
):
name
=
models
.
CharField
(
...
...
@@ -76,6 +93,9 @@ class Term(models.Model):
self
.
name
)
# Custom Manager
objects
=
TermManager
()
class
Meta
:
unique_together
=
(
'
name
'
,
'
taxonomy
'
)
index_together
=
[
'
name
'
,
'
taxonomy
'
]
This diff is collapsed.
Click to expand it.
django/website/taxonomies/tests/term_tests.py
0 → 100644
+
8
−
0
View file @
9e5cffae
from
__future__
import
unicode_literals
,
absolute_import
import
pytest
from
..models
import
Term
def
test_term_by_taxonomy
():
assert
False
,
"
Test not written yet
"
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment