You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There is no problem when tested as below. Give me more information.
serializer
class AddressSerializer(NestedHyperlinkedModelSerializer):
user = NestedHyperlinkedIdentityField(
view_name='user-detail',
parent_lookup_kwargs={
'user_pk': 'user__pk',
},
)
class Meta:
model = Address
fields = '__all__'
model
class Address(models.Model):
id = models.BigAutoField(primary_key=True)
user = models.ForeignKey(
User, on_delete=models.SET_NULL, related_name='addresses', null=True)
view
class AddressViewSet(viewsets.ModelViewSet):
serializer_class = AddressSerializer
def get_queryset(self):
return Address.objects.filter(user=self.kwargs['user_pk'])
Model
Serializer
I want child is
None
ifchild object
isNone
, instead of raiseAttributeError: 'NoneType' object has no attribute 'pk'
The text was updated successfully, but these errors were encountered: