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
7b7b7cee
authored
Feb 02, 2014
by
Florian Apolloner
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #181 from rizumu/get-prefetch-queryset
Get prefetch queryset
parents
a35236b2
15407771
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
8 deletions
+9
-8
taggit/managers.py
+9
-8
No files found.
taggit/managers.py
View file @
7b7b7cee
...
...
@@ -289,13 +289,13 @@ class _TaggableManager(models.Manager):
def
is_cached
(
self
,
instance
):
return
self
.
prefetch_cache_name
in
instance
.
_prefetched_objects_cache
def
get_query
_
set
(
self
):
def
get_queryset
(
self
):
try
:
return
self
.
instance
.
_prefetched_objects_cache
[
self
.
prefetch_cache_name
]
except
(
AttributeError
,
KeyError
):
return
self
.
through
.
tags_for
(
self
.
model
,
self
.
instance
)
def
get_prefetch_query
_set
(
self
,
instances
,
queryset
=
None
):
def
get_prefetch_query
set
(
self
,
instances
,
queryset
=
None
):
if
queryset
is
not
None
:
raise
ValueError
(
"Custom queryset can't be used for this lookup."
)
...
...
@@ -314,7 +314,7 @@ class _TaggableManager(models.Manager):
source_col
=
fk
.
column
connection
=
connections
[
db
]
qn
=
connection
.
ops
.
quote_name
qs
=
self
.
get_query
_
set
()
.
using
(
db
)
.
_next_is_sticky
()
.
filter
(
**
query
)
.
extra
(
qs
=
self
.
get_queryset
()
.
using
(
db
)
.
_next_is_sticky
()
.
filter
(
**
query
)
.
extra
(
select
=
{
'_prefetch_related_val'
:
'
%
s.
%
s'
%
(
qn
(
join_table
),
qn
(
source_col
))
}
...
...
@@ -325,8 +325,9 @@ class _TaggableManager(models.Manager):
False
,
self
.
prefetch_cache_name
)
# Django 1.6 renamed this
get_queryset
=
get_query_set
# Django < 1.6 uses the previous name of query_set
get_query_set
=
get_queryset
get_prefetch_query_set
=
get_prefetch_queryset
def
_lookup_kwargs
(
self
):
return
self
.
through
.
lookup_kwargs
(
self
.
instance
)
...
...
@@ -354,11 +355,11 @@ class _TaggableManager(models.Manager):
@require_instance_manager
def
names
(
self
):
return
self
.
get_query
_
set
()
.
values_list
(
'name'
,
flat
=
True
)
return
self
.
get_queryset
()
.
values_list
(
'name'
,
flat
=
True
)
@require_instance_manager
def
slugs
(
self
):
return
self
.
get_query
_
set
()
.
values_list
(
'slug'
,
flat
=
True
)
return
self
.
get_queryset
()
.
values_list
(
'slug'
,
flat
=
True
)
@require_instance_manager
def
set
(
self
,
*
tags
):
...
...
@@ -375,7 +376,7 @@ class _TaggableManager(models.Manager):
self
.
through
.
objects
.
filter
(
**
self
.
_lookup_kwargs
())
.
delete
()
def
most_common
(
self
):
return
self
.
get_query
_
set
()
.
annotate
(
return
self
.
get_queryset
()
.
annotate
(
num_times
=
models
.
Count
(
self
.
through
.
tag_relname
())
)
.
order_by
(
'-num_times'
)
...
...
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