set search & filter on organization - change on herd in cooperative
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
from apps.herd.web.api.v1.serializers import HerdSerializer, RancherSerializer
|
||||
from apps.core.mixins.search_mixin import DynamicSearchMixin
|
||||
from apps.authentication.api.v1.api import UserViewSet
|
||||
from common.helpers import get_organization_by_user
|
||||
from rest_framework.exceptions import APIException
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.decorators import action
|
||||
@@ -19,6 +20,8 @@ class HerdViewSet(viewsets.ModelViewSet):
|
||||
@transaction.atomic
|
||||
def create(self, request, *args, **kwargs):
|
||||
""" create herd with user """
|
||||
organization = get_organization_by_user(request.user)
|
||||
|
||||
if 'user' in request.data.keys():
|
||||
# create user if owner of herd is not exist
|
||||
user = CustomOperations().custom_create(
|
||||
@@ -29,6 +32,10 @@ class HerdViewSet(viewsets.ModelViewSet):
|
||||
owner = user['id']
|
||||
request.data.update({'owner': owner})
|
||||
|
||||
# if cooperative do not send in request, set my organization in it
|
||||
if 'cooperative' not in request.data.keys():
|
||||
request.data.update({'cooperative': organization.id})
|
||||
|
||||
serializer = self.serializer_class(data=request.data)
|
||||
if serializer.is_valid():
|
||||
serializer.save()
|
||||
|
||||
Reference in New Issue
Block a user