I am trying to return custom json with the following structure
[ {
'yesterday': [{'teams': "team a -team b", 'start_time': "0: 11", 'pick': "X2", 'score': "1:4", 'odds': 1.25, 'won_or_lost': "won", 'date': "2019-01-8"}],
'today': [{'teams': "team a -team b", 'start_time': "0: 11", 'pick': "X2", 'score': "1:4", 'odds': 1.25, 'won_or_lost': "won", 'date': "2019-01-8"}],
'tomorrow': [{'teams': "team a -team b", 'start_time': "0: 11", 'pick': "X2", 'score': "1:4", 'odds': 1.25, 'won_or_lost': "won", 'date': "2019-01-8"}]
}]
The following is my code:
serializer.py
class GamesSerializer(serializers.Serializer):
class Meta:
model = AllGames
fields = ('teams', 'start_time', 'pick',
'score', 'odds', 'won_or_lost', 'date')
class GamesViewSet(viewsets.ModelViewSet):
today_date = date_picker
yesterday = AllGames.objects.filter(
date=today_date(-1)).order_by('start_time', 'teams')
today = AllGames.objects.filter(
date=today_date(0)).order_by('start_time', 'teams')
tomorrow = AllGames.objects.filter(
date=today_date(1)).order_by('start_time', 'teams')
queryset = [yesterday, today, tomorrow]
serializer_class = GamesSerializer
Current Output
[
{},
{},
{}
]
How can I modify my GamesSerializer to return the custom output as shown above.