Skip to content
GitLab
Menu
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
9aa06bbc
Commit
9aa06bbc
authored
Nov 22, 2014
by
Aymeric Barantal
Browse files
transform Group.type into a GroupType model and make it organization admin view aware
parent
72af5396
Changes
2
Hide whitespace changes
Inline
Side-by-side
picampaign/organization/admin.py
View file @
9aa06bbc
from
django.contrib
import
admin
from
picampaign.organization.models
import
(
Organization
,
Group
,
from
picampaign.organization.models
import
(
Organization
,
Group
,
GroupType
,
FeedbackCategory
)
...
...
@@ -12,6 +12,16 @@ class OrganizationAdmin(admin.ModelAdmin):
return
qs
.
filter
(
id__in
=
user_orgs
)
class
GroupTypeAdmin
(
admin
.
ModelAdmin
):
def
get_queryset
(
self
,
request
):
qs
=
super
(
GroupTypeAdmin
,
self
).
get_queryset
(
request
)
if
request
.
user
.
is_superuser
:
return
qs
user_orgs
=
[
x
.
id
for
x
in
request
.
user
.
organizations
.
all
()]
return
qs
.
filter
(
organization__in
=
user_orgs
)
class
GroupAdmin
(
admin
.
ModelAdmin
):
def
get_queryset
(
self
,
request
):
qs
=
super
(
GroupAdmin
,
self
).
get_queryset
(
request
)
...
...
@@ -31,5 +41,6 @@ class CategoryAdmin(admin.ModelAdmin):
admin
.
site
.
register
(
Organization
,
OrganizationAdmin
)
admin
.
site
.
register
(
GroupType
,
GroupTypeAdmin
)
admin
.
site
.
register
(
Group
,
GroupAdmin
)
admin
.
site
.
register
(
FeedbackCategory
,
CategoryAdmin
)
picampaign/organization/models.py
View file @
9aa06bbc
...
...
@@ -14,12 +14,21 @@ class Organization(models.Model):
return
self
.
name
class
GroupType
(
models
.
Model
):
id
=
models
.
AutoField
(
primary_key
=
True
)
organization
=
models
.
ForeignKey
(
Organization
)
name
=
models
.
CharField
(
max_length
=
64
)
def
__unicode__
(
self
):
return
self
.
name
class
Group
(
models
.
Model
):
"""Group model to qualify contacts"""
id
=
models
.
AutoField
(
primary_key
=
True
)
organization
=
models
.
ForeignKey
(
Organization
)
name
=
models
.
CharField
(
max_length
=
64
)
type
=
models
.
CharField
(
max_length
=
255
,
blank
=
True
)
type
=
models
.
ForeignKey
(
GroupType
,
blank
=
True
,
null
=
True
)
media
=
models
.
CharField
(
max_length
=
255
,
blank
=
True
)
contacts
=
models
.
ManyToManyField
(
Contact
,
null
=
True
,
blank
=
True
,
related_name
=
'groups'
)
...
...
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