I have the following model skeletons:
class A(models.Model):
post_id = models.ForeignKey('D')
user_id = models.ForeignKey('B')
class B(AbstractBaseUser):
email = models.EmailField(unique=True)
username = models.CharField(max_length=20, unique=True)
first_name = models.CharField(max_length=40)
last_name = models.CharField(max_length=40)
# `resource_id`
profile_photo = models.ForeignKey('C', null=True)
class C(models.Model):
user_id = models.ForeignKey('B')
name = models.CharField(max_length=60)
I want to write a serializer for A which should return name from model C, which is related to B.
The relation here is like A->B->C Now using A's serializer I want data to be fetched from C
I want to access C via A i.e get profile_photo from B and the get the name of profile_photo from C
I scrolled through RelatedFields as given here Django Rest relations but am not able to achieve what I want.
Is their any way I can achieve it.
Also there are a lot of fields other than mentioned in the model skeleton and I do not want to fetch those.
EDIT:
The final result I need is the all the user_id for a particular post_id from A with the name from model C