Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
hypha
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
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
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
ots
hypha
Commits
31b4389a
Commit
31b4389a
authored
7 years ago
by
Todd Dembrey
Browse files
Options
Downloads
Patches
Plain Diff
Make querying over wagtail objects easier
parent
1e55d2ad
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
opentech/apply/dashboard/tables.py
+25
-1
25 additions, 1 deletion
opentech/apply/dashboard/tables.py
with
25 additions
and
1 deletion
opentech/apply/dashboard/tables.py
+
25
−
1
View file @
31b4389a
...
...
@@ -58,11 +58,35 @@ class Select2ModelMultipleChoiceFilter(Select2MultipleChoiceFilter, filters.Mode
pass
class
WagtailMulitChoiceFilter
(
Select2ModelMultipleChoiceFilter
):
@property
def
wagtail_query
(
self
):
# Queries on related pages will first attempt to query through the Page object
def
is_page
(
relation
):
return
relation
.
field
.
related_model
==
Page
wagtail_path
=
list
()
steps
=
self
.
field_name
.
split
(
'
__
'
)
related_item
=
self
.
model
for
step
in
steps
:
related_item
=
getattr
(
related_item
,
step
)
wagtail_path
.
append
(
step
)
if
is_page
(
related_item
):
# Traverse over the page object to get the model at the other end
related_item
=
getattr
(
related_item
.
field
.
related_model
,
step
).
related
.
remote_field
.
model
wagtail_path
.
append
(
step
)
return
'
__
'
.
join
(
wagtail_path
)
def
get_filter_predicate
(
self
,
v
):
return
{
self
.
wagtail_query
:
v
}
class
SubmissionFilter
(
filters
.
FilterSet
):
round
=
Select2ModelMultipleChoiceFilter
(
queryset
=
get_used_rounds
,
label
=
'
Rounds
'
)
funds
=
Select2ModelMultipleChoiceFilter
(
name
=
'
page
'
,
queryset
=
get_used_funds
,
label
=
'
Funds
'
)
status
=
Select2MultipleChoiceFilter
(
name
=
'
status__contains
'
,
choices
=
status_options
,
label
=
'
Status
'
)
lead
=
Select2ModelMultiple
ChoiceFilter
(
name
=
'
round__lead
'
,
queryset
=
get_round_leads
,
label
=
'
Lead
'
)
lead
=
WagtailMulit
ChoiceFilter
(
name
=
'
round__lead
'
,
queryset
=
get_round_leads
,
label
=
'
Lead
'
)
class
Meta
:
model
=
ApplicationSubmission
...
...
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