fix edit user bug
This commit is contained in:
@@ -140,7 +140,7 @@ class UserSerializer(serializers.ModelSerializer):
|
|||||||
instance.address = validated_data.get('address')
|
instance.address = validated_data.get('address')
|
||||||
instance.photo = validated_data.get('photo')
|
instance.photo = validated_data.get('photo')
|
||||||
instance.province = validated_data.get('province', instance.province)
|
instance.province = validated_data.get('province', instance.province)
|
||||||
instance.city = validated_data.get('province', instance.province)
|
instance.city = validated_data.get('city', instance.city)
|
||||||
instance.otp_status = validated_data.get('otp_status')
|
instance.otp_status = validated_data.get('otp_status')
|
||||||
instance.save()
|
instance.save()
|
||||||
|
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ class RancherViewSet(viewsets.ModelViewSet, DynamicSearchMixin):
|
|||||||
def list(self, request, *args, **kwargs):
|
def list(self, request, *args, **kwargs):
|
||||||
""" list of ranchers """
|
""" list of ranchers """
|
||||||
|
|
||||||
search = self.filter_query(self.queryset) # search & filter
|
search = self.filter_query(self.queryset.order_by('-modify_date')) # search & filter
|
||||||
page = self.paginate_queryset(search)
|
page = self.paginate_queryset(search)
|
||||||
if page is not None:
|
if page is not None:
|
||||||
serializer = self.get_serializer(page, many=True)
|
serializer = self.get_serializer(page, many=True)
|
||||||
@@ -116,6 +116,18 @@ class RancherViewSet(viewsets.ModelViewSet, DynamicSearchMixin):
|
|||||||
@action(
|
@action(
|
||||||
methods=['get'],
|
methods=['get'],
|
||||||
detail=True,
|
detail=True,
|
||||||
|
url_path='herds',
|
||||||
|
url_name='herds',
|
||||||
|
name='herds'
|
||||||
)
|
)
|
||||||
def herds_by_rancher(self, request):
|
def herds_by_rancher(self, request, pk=None):
|
||||||
pass
|
""" list of rancher herds """
|
||||||
|
|
||||||
|
rancher = self.get_object()
|
||||||
|
queryset = rancher.herd.all() # get rancher herds
|
||||||
|
|
||||||
|
# paginate queryset
|
||||||
|
page = self.paginate_queryset(queryset)
|
||||||
|
if page is not None:
|
||||||
|
serializer = HerdSerializer(page, many=True)
|
||||||
|
return self.get_paginated_response(serializer.data)
|
||||||
|
|||||||
@@ -18,11 +18,12 @@ class HerdSerializer(serializers.ModelSerializer):
|
|||||||
""" Customize serializer output """
|
""" Customize serializer output """
|
||||||
representation = super().to_representation(instance)
|
representation = super().to_representation(instance)
|
||||||
if isinstance(instance, Herd):
|
if isinstance(instance, Herd):
|
||||||
representation['owner'] = UserSerializer(instance.owner).data
|
representation['owner'] = instance.owner.id
|
||||||
representation['cooperative'] = OrganizationSerializer(instance.cooperative).data
|
representation['cooperative'] = OrganizationSerializer(instance.cooperative).data
|
||||||
representation['province'] = ProvinceSerializer(instance.province).data
|
representation['province'] = ProvinceSerializer(instance.province).data
|
||||||
representation['city'] = CitySerializer(instance.city).data
|
representation['city'] = CitySerializer(instance.city).data
|
||||||
representation['contractor'] = OrganizationSerializer(instance.contractor).data
|
representation['contractor'] = OrganizationSerializer(instance.contractor).data
|
||||||
|
representation['rancher'] = RancherSerializer(instance.rancher).data
|
||||||
|
|
||||||
return representation
|
return representation
|
||||||
|
|
||||||
@@ -33,6 +34,8 @@ class RancherSerializer(serializers.ModelSerializer):
|
|||||||
fields = '__all__'
|
fields = '__all__'
|
||||||
|
|
||||||
def to_representation(self, instance):
|
def to_representation(self, instance):
|
||||||
|
""" customize output of serializer """
|
||||||
|
|
||||||
representation = super().to_representation(instance)
|
representation = super().to_representation(instance)
|
||||||
|
|
||||||
representation['province'] = {
|
representation['province'] = {
|
||||||
|
|||||||
Reference in New Issue
Block a user