yezyilomo / django-restql

Turn your API made with Django REST Framework(DRF) into a GraphQL like API.
https://yezyilomo.github.io/django-restql
MIT License
620 stars 43 forks source link

how can use NestedField (with accept_pk_only) on DynamicFieldsMixin? #207

Open alinajafi321 opened 3 years ago

alinajafi321 commented 3 years ago

Hi, I use NestedField (with accept_pk_only) on DynamicFieldsMixin and i get this result: 'int' object has no attribute 'get'

Can you help me to solve this problem?

yezyilomo commented 3 years ago

Hi, I use NestedField (with accept_pk_only) on DynamicFieldsMixin and i get this result: 'int' object has no attribute 'get'

Can you help me to solve this problem?

Posting a segment of code with a problem would be helpful to someone who wants to help.

alinajafi321 commented 3 years ago

I just want

class TicketingSerializer(DynamicFieldsMixin):
    shift = CartAppSerializer.ShiftSerializer(read_only=True,allow_null=True, required=False)
    shift_id = PKR(queryset=CartAppSerializer.Shift.objects.all(), source="shift", allow_null=True, required=False)

To

class TicketingSerializer(DynamicFieldsMixin):
    shift = NestedField(ShiftSerializer, accept_pk_only=True)

For example : send request:

{
name:"new ticket"
shift:1
}

in response: 'int' object has no attribute 'get'

sommelon commented 3 years ago

Try adding NestedModelSerializer to the serializer definition like this:

from django_restql.serializers import NestedModelSerializer

class TicketingSerializer(DynamicFieldsMixin, NestedModelSerializer):

If you get the same error, post the entire error trace.