Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Backend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Arkindex
Backend
Commits
1e0e68dc
Commit
1e0e68dc
authored
6 years ago
by
Erwan Rouchet
Browse files
Options
Downloads
Patches
Plain Diff
Add get_ascendings
parent
b9910ab7
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!18
Transcription search
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/documents/managers.py
+10
-0
10 additions, 0 deletions
src/documents/managers.py
with
10 additions
and
0 deletions
src/documents/managers.py
+
10
−
0
View file @
1e0e68dc
from
django.db
import
models
from
itertools
import
groupby
class
DocumentManager
(
models
.
Manager
):
...
...
@@ -8,6 +9,15 @@ class DocumentManager(models.Manager):
"""
Get all parent documents for a specific document ID.
"""
return
self
.
filter
(
dp_parent__id
=
id
).
order_by
(
'
dp_parent__ordering
'
)
def
get_ascendings
(
self
,
*
ids
):
"""
Get all parent documents for some document IDs.
"""
from
documents.models
import
DocumentParents
dps
=
DocumentParents
.
objects
.
filter
(
id__in
=
ids
).
order_by
(
'
id
'
,
'
ordering
'
).
only
(
'
id
'
,
'
parent
'
).
select_related
(
'
parent
'
)
return
{
pk
:
[
dp
.
parent
for
dp
in
items
]
for
pk
,
items
in
groupby
(
dps
,
lambda
d
:
d
.
id
)
}
def
get_descending
(
self
,
id
):
"""
Get all child documents for a specific document ID.
"""
return
self
.
filter
(
dc_child__id
=
id
).
order_by
(
'
dc_child__ordering
'
)
...
...
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