File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 148148# The directory to store images and other media
149149MEDIA_ROOT = BASE_DIR / "media"
150150
151- # The url to serve images and other media
152- if DEBUG :
153- MEDIA_URL = "http://localhost:8000/media/"
154- else :
155- MEDIA_URL = f"https://{ ALLOWED_HOSTS [0 ]} /media/"
151+ MEDIA_URL = "/media/"
156152
157153DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
158154
Original file line number Diff line number Diff line change @@ -100,17 +100,7 @@ def get_contributors(self, obj):
100100 return ShowcaseContributorSerializer (contributors , many = True ).data
101101
102102
103- class ContributorGameDataSerializer (serializers .ModelSerializer ):
104- # Serializes data in Game model to display on a contributor's profile.
105-
106- class Meta :
107- model = Game
108- fields = ('name' , 'thumbnail' ,
109- 'description' )
110-
111-
112103class ContributorGameSerializer (serializers .ModelSerializer ):
113- # Matches games in the GameContributor model to the information about them in the Game model.
114104 game_id = serializers .IntegerField (source = 'game.id' , read_only = True )
115105 role = serializers .CharField (read_only = True )
116106 game_data = serializers .SerializerMethodField ()
@@ -120,8 +110,13 @@ class Meta:
120110 fields = ['game_id' , 'role' , 'game_data' ]
121111
122112 def get_game_data (self , obj ):
123- game_data = Game .objects .get (id = obj .game_id )
124- return ContributorGameDataSerializer (game_data ).data
113+ game = obj .game
114+ request = self .context .get ('request' )
115+ return {
116+ 'name' : game .name ,
117+ 'description' : game .description ,
118+ 'thumbnail' : request .build_absolute_uri (game .thumbnail .url ) if game .thumbnail and request else None
119+ }
125120
126121
127122class SocialMediaSerializer (serializers .ModelSerializer ):
Original file line number Diff line number Diff line change @@ -70,18 +70,12 @@ def get(self, request):
7070 return Response (serializer .data )
7171
7272
73- class ContributorGamesListAPIView (APIView ):
74- """
75- GET /api/games/contributor/<member>/
76- Returns the games a particular member has contributed to.
77- """
78- lookup_url_kwarg = "member"
73+ class ContributorGamesListAPIView (generics .ListAPIView ):
74+ serializer_class = ContributorGameSerializer
7975
80- def get (self , request , member ):
81- contributions = GameContributor .objects .filter (
82- member = self .kwargs ["member" ])
83- serializer = ContributorGameSerializer (contributions , many = True )
84- return Response (serializer .data )
76+ def get_queryset (self ):
77+ member_id = self .kwargs .get ("member" )
78+ return GameContributor .objects .filter (member = member_id )
8579
8680
8781class MemberAPIView (generics .RetrieveAPIView ):
You can’t perform that action at this time.
0 commit comments