Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes 206, 240 #241

Merged
merged 1 commit into from
Jan 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions event/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ def get_queryset(self, request):
org = Organisation.objects.filter(owner=request.user)
return Event.objects.filter(organisation__in=org)

# Overriding event form to not allow user to create organisation at the time of creating event
def get_form(self, request, obj=None, **kwargs):
form = super(EventAdmin, self).get_form(request, obj, **kwargs)
widget = form.base_fields['organisation'].widget
widget.can_add_related = False
return form

# pylint: disable=W0222
def formfield_for_foreignkey(self, db_field, request, **kwargs):
# when we are creating or editing new event and the logged in user is not superuser
Expand Down
8 changes: 5 additions & 3 deletions organisation/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from rest_framework import viewsets, status
from .models import Organisation
from event.models import Event
from event.serializers import EventSerializer
from .serializer import OrganisationSerializer, OrganisationCreateSerializer
# Create your views here.
from rest_framework.response import Response
Expand All @@ -23,9 +24,10 @@ def retrieve(self,request,pk=None):
queryset_organisation = Organisation.objects.get(pk=pk)
except Organisation.DoesNotExist:
raise Http404
queryset_event = Event.objects.filter(organisation=pk).values()
queryset_event = Event.objects.filter(organisation=pk)
serialized_data_events = EventSerializer(queryset_event, many=True)
serialized_data_organisation = OrganisationSerializer(queryset_organisation)
data = { **serialized_data_organisation.data }
data['events'] = queryset_event
data = { **serialized_data_organisation.data}
data['events'] = serialized_data_events.data

return Response(data, status=status.HTTP_200_OK)