Commit 4292aa1c authored by okhin's avatar okhin 🚴

Merge branch...

Merge branch '21-an-organization-does-not-appears-in-the-selectable-one-for-a-campaign' into 'master'

Resolve "An organization does not appears in the selectable one for a campaign`"

Closes #21

See merge request !11
parents 75b91752 7387b018
Pipeline #1243 passed with stages
in 2 minutes and 1 second
...@@ -33,10 +33,11 @@ class CampaignAdmin(TranslationAdmin): ...@@ -33,10 +33,11 @@ class CampaignAdmin(TranslationAdmin):
def formfield_for_foreignkey(self, db_field, request, **kwargs): def formfield_for_foreignkey(self, db_field, request, **kwargs):
if db_field.name == "organization": if db_field.name == "organization":
if request.user.is_superuser: if request.user.is_superuser:
kwargs["queryset"] = Organization.objects.all() orgs = Organization.objects.all()
else: else:
orgs = request.user.organizations.all()
query = {'id__in': [x.id query = {'id__in': [x.id
for x in request.user.organizations.all()]} for x in orgs]}
kwargs["queryset"] = Organization.objects.filter(**query) kwargs["queryset"] = Organization.objects.filter(**query)
return super(CampaignAdmin, self).formfield_for_foreignkey(db_field, return super(CampaignAdmin, self).formfield_for_foreignkey(db_field,
request, request,
...@@ -69,6 +70,9 @@ class ArgumentaryAdmin(TranslationAdmin): ...@@ -69,6 +70,9 @@ class ArgumentaryAdmin(TranslationAdmin):
def formfield_for_foreignkey(self, db_field, request, **kwargs): def formfield_for_foreignkey(self, db_field, request, **kwargs):
if db_field.name == "campaign": if db_field.name == "campaign":
if request.user.is_superuser:
orgs = Organization.objects.all()
else:
orgs = request.user.organizations.all() orgs = request.user.organizations.all()
query = {'organization__in': orgs} query = {'organization__in': orgs}
kwargs["queryset"] = Campaign.objects.filter(**query) kwargs["queryset"] = Campaign.objects.filter(**query)
......
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