@@ -18,12 +18,18 @@ class Meta:
1818
1919# This is child serializer of GameSerializer
2020class GameContributorSerializer (serializers .ModelSerializer ):
21- member_id = serializers .IntegerField (source = "member.id" ) # to link contributors to their member/[id] page
21+ # to link contributors to their member/[id] page
22+ member_id = serializers .IntegerField (source = "member.id" )
2223 name = serializers .CharField (source = "member.name" )
24+ social_media = serializers .SerializerMethodField ()
2325
2426 class Meta :
2527 model = GameContributor
26- fields = ("member_id" , "name" , "role" )
28+ fields = ("member_id" , "name" , "role" , "social_media" )
29+
30+ def get_social_media (self , obj ):
31+ social_links = obj .member .social_media_links .all ()
32+ return SocialMediaSerializer (social_links , many = True ).data
2733
2834
2935class GamesSerializer (serializers .ModelSerializer ):
@@ -35,32 +41,40 @@ class GamesSerializer(serializers.ModelSerializer):
3541
3642 class Meta :
3743 model = Game
38- fields = ('id' , 'name' , 'description' , 'completion' , 'active' , 'hostURL' , 'itchEmbedID' , 'thumbnail' , 'event' , "contributors" )
44+ fields = ('id' , 'name' , 'description' , 'completion' , 'active' ,
45+ 'hostURL' , 'itchEmbedID' , 'thumbnail' , 'event' , "contributors" )
3946
4047
4148# Contributor serializer for name and role
49+
4250class ShowcaseContributorSerializer (serializers .ModelSerializer ):
4351 name = serializers .CharField (source = 'member.name' , read_only = True )
4452 role = serializers .CharField (read_only = True )
45- # social_links = serializers.CharField(source='member.social_links', read_only=True)
46- # socialmedia_name = serializers.CharField(source='member.socialmedia_name', read_only=True)
53+ social_media = serializers .SerializerMethodField ()
4754
4855 class Meta :
4956 model = GameContributor
50- fields = ("name" , "role" )
57+ fields = ("name" , "role" , "social_media" )
58+
59+ def get_social_media (self , obj ):
60+ social_links = obj .member .social_media_links .all ()
61+ return SocialMediaSerializer (social_links , many = True ).data
5162
5263
5364# Serializer for GameShowcase
5465class GameshowcaseSerializer (serializers .ModelSerializer ):
5566 game_id = serializers .IntegerField (source = 'game.id' , read_only = True )
5667 game_name = serializers .CharField (source = 'game.name' , read_only = True )
57- game_description = serializers .CharField (source = 'game.description' , read_only = True )
58- game_cover_thumbnail = serializers .ImageField (source = 'game.thumbnail' , read_only = True )
68+ game_description = serializers .CharField (
69+ source = 'game.description' , read_only = True )
70+ game_cover_thumbnail = serializers .ImageField (
71+ source = 'game.thumbnail' , read_only = True )
5972 contributors = serializers .SerializerMethodField ()
6073
6174 class Meta :
6275 model = GameShowcase
63- fields = ('game_id' , 'game_name' , 'game_description' , 'description' , 'contributors' , 'game_cover_thumbnail' )
76+ fields = ('game_id' , 'game_name' , 'game_description' ,
77+ 'description' , 'contributors' , 'game_cover_thumbnail' )
6478
6579 def get_contributors (self , obj ):
6680 # Always fetch contributors from GameContributor for the related game
@@ -79,7 +93,9 @@ class Meta:
7993
8094
8195class MemberSerializer (serializers .ModelSerializer ):
82- social_media = SocialMediaSerializer (many = True , source = "social_media_links" , read_only = True )
96+ social_media = SocialMediaSerializer (
97+ many = True , source = "social_media_links" , read_only = True )
98+
8399 class Meta :
84100 model = Member
85101 fields = [
0 commit comments