I have the following model
class Contact(models.Model):
user = models.ForeignKey(CustomUser, on_delete=models.CASCADE, related_name='contacts')
friends = models.ManyToManyField('self', blank=True)
def __str__(self):
return self.user.username
When the user log-in, the client make a HTTP request to the following view to get user friends.
class ContactAPIView(generics.RetrieveAPIView):
queryset = Contact.objects.all()
serializer_class = ContactSerializer
lookup_field = 'user__username'
The data returned:
THE QUESTION IS:
How can I serializer the 'friends' field in a way that I can get the id, user.id and user.username.
