Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
alinajafi321 opened this issue Apr 28, 2021 · 3 comments
Open

Comments

@alinajafi321
Copy link

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
Copy link
Owner

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
Copy link
Author

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
Copy link

sommelon commented May 11, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants