Question:In my project, I have three models:
Challenge. Each user is a member of some groups and each challenge is intended for one or more groups.
Challengemodels that serializes all challenge data and related groups using a
Challengeobject, a list of all related groups is serialized.
Is it possible to only serialize related
Groupobjects that are also related to our currently logged in user?
Answer:you could use a
SerializerMethodField()to filter down the Challenges groups to just the user groups. To do this you may also need to pass in serializer context as well
To set up the serializer context:
SerializerMethodFieldin your serializer
ChallengeListto improve performance
If you have better answer, please add a comment about this, thank you!