Untitled
unknown
plain_text
2 years ago
941 B
7
Indexable
class UserGamesList(generics.RetrieveAPIView):
queryset = Account.objects.all()
serializer_class = AccountSerializer
permission_classes = [permissions.AllowAny]
lookup_field = 'username'
def get_object(self):
return Account.objects.get(username=self.kwargs['username'])
def get(self, request, *args, **kwargs):
user = self.get_object()
games = Game.objects.filter(players=user)
games_list = []
for game in games:
scores = game.scores.all()
scores_str = ' - '.join([f"{score.score}" for score in scores])
games_list.append(
{
"game_id": game.id,
"date_begin": game.date_begin,
"status": game.status,
"room_id": game.room_id,
"scores": scores_str
}
)
return Response({"games": games_list})Editor is loading...
Leave a Comment