Commit 9aa06bbc authored by Aymeric Barantal's avatar Aymeric Barantal

transform Group.type into a GroupType model and make it organization admin view aware

parent 72af5396
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)
......@@ -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')
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment