django-restql icon indicating copy to clipboard operation
django-restql copied to clipboard

how can use NestedField (with accept_pk_only) on DynamicFieldsMixin?

Open alinajafi321 opened this issue 4 years ago • 3 comments

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?

alinajafi321 avatar Apr 28 '21 05:04 alinajafi321

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.

yezyilomo avatar Apr 28 '21 07:04 yezyilomo

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'

alinajafi321 avatar Apr 29 '21 03:04 alinajafi321

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.

sommelon avatar May 11 '21 12:05 sommelon