Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
La Quadrature du Net
piphone
campaign
Commits
3f000279
Commit
3f000279
authored
Nov 23, 2014
by
Aymeric Barantal
Browse files
filter available organization and campaign in admin forms, second part
parent
b19fcb0c
Changes
2
Hide whitespace changes
Inline
Side-by-side
picampaign/campaign/admin.py
View file @
3f000279
...
...
@@ -50,7 +50,6 @@ class ArgumentaryAdmin(admin.ModelAdmin):
if
db_field
.
name
==
"campaign"
:
orgs
=
request
.
user
.
organizations
.
all
()
query
=
{
'organization__in'
:
orgs
}
print
"##### QUERY %r"
%
query
kwargs
[
"queryset"
]
=
Campaign
.
objects
.
filter
(
**
query
)
return
super
(
ArgumentaryAdmin
,
self
).
formfield_for_foreignkey
(
db_field
,
request
,
...
...
picampaign/organization/admin.py
View file @
3f000279
...
...
@@ -21,6 +21,15 @@ class GroupTypeAdmin(admin.ModelAdmin):
user_orgs
=
[
x
.
id
for
x
in
request
.
user
.
organizations
.
all
()]
return
qs
.
filter
(
organization__in
=
user_orgs
)
def
formfield_for_foreignkey
(
self
,
db_field
,
request
,
**
kwargs
):
if
db_field
.
name
==
"organization"
:
orgs
=
request
.
user
.
organizations
.
all
()
query
=
{
'id__in'
:
orgs
}
kwargs
[
"queryset"
]
=
Organization
.
objects
.
filter
(
**
query
)
return
super
(
GroupTypeAdmin
,
self
).
formfield_for_foreignkey
(
db_field
,
request
,
**
kwargs
)
class
GroupAdmin
(
admin
.
ModelAdmin
):
def
get_queryset
(
self
,
request
):
...
...
@@ -30,6 +39,19 @@ class GroupAdmin(admin.ModelAdmin):
user_orgs
=
[
x
.
id
for
x
in
request
.
user
.
organizations
.
all
()]
return
qs
.
filter
(
organization__in
=
user_orgs
)
def
formfield_for_foreignkey
(
self
,
db_field
,
request
,
**
kwargs
):
if
db_field
.
name
==
"organization"
:
orgs
=
request
.
user
.
organizations
.
all
()
query
=
{
'id__in'
:
orgs
}
kwargs
[
"queryset"
]
=
Organization
.
objects
.
filter
(
**
query
)
elif
db_field
.
name
==
"type"
:
orgs
=
request
.
user
.
organizations
.
all
()
query
=
{
'organization__in'
:
orgs
}
kwargs
[
"queryset"
]
=
GroupType
.
objects
.
filter
(
**
query
)
return
super
(
GroupAdmin
,
self
).
formfield_for_foreignkey
(
db_field
,
request
,
**
kwargs
)
class
CategoryAdmin
(
admin
.
ModelAdmin
):
def
get_queryset
(
self
,
request
):
...
...
@@ -39,6 +61,15 @@ class CategoryAdmin(admin.ModelAdmin):
user_orgs
=
[
x
.
id
for
x
in
request
.
user
.
organizations
.
all
()]
return
qs
.
filter
(
organization__in
=
user_orgs
)
def
formfield_for_foreignkey
(
self
,
db_field
,
request
,
**
kwargs
):
if
db_field
.
name
==
"organization"
:
orgs
=
request
.
user
.
organizations
.
all
()
query
=
{
'id__in'
:
orgs
}
kwargs
[
"queryset"
]
=
Organization
.
objects
.
filter
(
**
query
)
return
super
(
CategoryAdmin
,
self
).
formfield_for_foreignkey
(
db_field
,
request
,
**
kwargs
)
admin
.
site
.
register
(
Organization
,
OrganizationAdmin
)
admin
.
site
.
register
(
GroupType
,
GroupTypeAdmin
)
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment