I have this serializer and model. I want to show in my API the field username of User model, but I receive this error.
AttributeError at /api/v1/client_share_requests/1/
'Profile' object has no attribute 'username'
serializers.py
class ClientShareRequestSerializer(serializers.ModelSerializer):checked_by = serializers.SlugRelatedField(many=True,queryset=Profile.objects.all(),slug_field='username')class Meta:model = ClientShareRequestfields = ('checked_by')
models.py
class Profile(models.Model):user = models.OneToOneField(User, related_name='profile')class ClientShareRequest(models.Model):checked_by = models.ManyToManyField(Profile, blank=True,related_name='checked_by')
I try to access the User model instance like this:
checked_by = serializers.SlugRelatedField(many=True,queryset=Profile.objects.all(),slug_field='user.username')
but I receive this error:
'Profile' object has no attribute 'user.username'
Thanks for helping. (Sorry for my English :P)