0

serializers.py -while joining HiringstatusSerializer in DriverEditListSerializer getting error

class CitySerializer(serializers.ModelSerializer):
    class Meta:
        model = City
        fields = ('id', 'name')
class LocationSerializer(serializers.ModelSerializer):
     class Meta:
        model = Location
        fields = ('id', 'name')
class HiringstatusSerializer(serializers.ModelSerializer):
     class Meta:
        model = Hiring
        fields = ('driver_id', 'status')
class DriverEditListSerializer(serializers.ModelSerializer):
    city = CitySerializer(read_only=True)
    location = LocationSerializer()
    hstatus=HiringstatusSerializer()
    class Meta:
        model = Driver
        fields = ( 'id','employee_id','employer', 'name','uber_name','uber_device_no', 'mobile', 'location', 'city','shift','status', 'aadhar_no','hstatus')

views.py

class DriverViewSet(viewsets.ModelViewSet):
    queryset = Driver.objects.filter(is_active=1)
    serializer_class = DriverEditListSerializer

    def get_queryset(self):
        queryset = Driver.objects.filter(is_active=1, city_id=self.request.GET.get('city_id'))
        return queryset

output error this is output error while hit url

    raise type(exc)(msg)
AttributeError: Got AttributeError when attempting to get a value for field `hstatus` on serializer `DriverEditListSerializer`.
The serializer field might be named incorrectly and not match any attribute or key on the `Driver` instance.
Original exception text was: 'Driver' object has no attribute 'hstatus'.
ERROR "GET /fleet/dt/editdrivers/ HTTP/1.1" 500 187937
2

1 Answer 1

0

in your nested serializer pass these arguments.

class DriverEditListSerializer(serializers.ModelSerializer):
    city = CitySerializer(many=True, required=False, allow_null=True)
    location = LocationSerializer(many=True, required=False, allow_null=True)
    hstatus=HiringstatusSerializer(many=True, required=False, allow_null=True)
    class Meta:
        model = Driver
        fields = ( 'id','employee_id','employer', 'name','uber_name','uber_device_no', 'mobile', 'location', 'city','shift','status', 'aadhar_no','hstatus')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.