add city & province name to user serializer
This commit is contained in:
@@ -94,6 +94,11 @@ class UserSerializer(serializers.ModelSerializer):
|
|||||||
'otp_status',
|
'otp_status',
|
||||||
'is_herd_owner',
|
'is_herd_owner',
|
||||||
]
|
]
|
||||||
|
extra_kwargs = {
|
||||||
|
'password': {
|
||||||
|
'required': False
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
def to_representation(self, instance):
|
def to_representation(self, instance):
|
||||||
""" Custom output """
|
""" Custom output """
|
||||||
@@ -105,10 +110,8 @@ class UserSerializer(serializers.ModelSerializer):
|
|||||||
).data
|
).data
|
||||||
|
|
||||||
if instance.city:
|
if instance.city:
|
||||||
representation['city_id'] = instance.city.id
|
|
||||||
representation['city_name'] = instance.city.name
|
representation['city_name'] = instance.city.name
|
||||||
if instance.province:
|
if instance.province:
|
||||||
representation['province_id'] = instance.province.id
|
|
||||||
representation['province_name'] = instance.province.name
|
representation['province_name'] = instance.province.name
|
||||||
|
|
||||||
return representation
|
return representation
|
||||||
|
|||||||
@@ -25,12 +25,30 @@ def delete(queryset, pk):
|
|||||||
|
|
||||||
|
|
||||||
class QuotaDistributionViewSet(viewsets.ModelViewSet):
|
class QuotaDistributionViewSet(viewsets.ModelViewSet):
|
||||||
|
""" quota distribution apis """
|
||||||
|
|
||||||
queryset = product_models.QuotaDistribution.objects.all()
|
queryset = product_models.QuotaDistribution.objects.all()
|
||||||
serializer_class = distribution_serializers.QuotaDistributionSerializer
|
serializer_class = distribution_serializers.QuotaDistributionSerializer
|
||||||
|
|
||||||
@transaction.atomic
|
@transaction.atomic
|
||||||
def create(self, request, *args, **kwargs):
|
def create(self, request, *args, **kwargs):
|
||||||
pass
|
""" create distribution for organizations users """
|
||||||
|
|
||||||
|
# get distributed assigner user
|
||||||
|
try:
|
||||||
|
assigner_user = product_models.UserRelations.objects.filter(
|
||||||
|
user=request.user
|
||||||
|
).first()
|
||||||
|
except APIException as e:
|
||||||
|
raise APIException("unauthorized", code=status.HTTP_401_UNAUTHORIZED)
|
||||||
|
|
||||||
|
request.data.update({'assigner_organization': assigner_user.id})
|
||||||
|
|
||||||
|
serializer = self.serializer_class(data=request.data)
|
||||||
|
if serializer.is_valid(raise_exception=True):
|
||||||
|
serializer.save()
|
||||||
|
return Response(serializer.data, status=status.HTTP_201_CREATED)
|
||||||
|
return Response(serializer.errors, status=status.HTTP_403_FORBIDDEN)
|
||||||
|
|
||||||
@action(
|
@action(
|
||||||
methods=['put'],
|
methods=['put'],
|
||||||
@@ -62,5 +80,3 @@ class QuotaDistributionViewSet(viewsets.ModelViewSet):
|
|||||||
return Response(status=status.HTTP_200_OK)
|
return Response(status=status.HTTP_200_OK)
|
||||||
except APIException as e:
|
except APIException as e:
|
||||||
return Response(e, status=status.HTTP_204_NO_CONTENT)
|
return Response(e, status=status.HTTP_204_NO_CONTENT)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user