def create_default_trade(): pokemon1 = {'name': 'pikachu', 'base_experience': 112, 'image': 'url'} pokemon2 = {'name': 'charmander', 'base_experience': 62, 'image': 'url'} trade = Trade() trade.right_side = [pokemon1, pokemon2] trade.left_side = [pokemon1, pokemon2] trade.result = trade.is_fair() return trade
def save(self, request): """ Save a specific trade in database. It is done if the user accept the trade. It is used to populate the database with all trades that was made with PokeTrader. """ trade_serializer = TradeSerializer(data=request.data) if trade_serializer.is_valid(): trade = Trade(right_side=trade_serializer.validated_data['right_side'], left_side=trade_serializer.validated_data['left_side']) trade.result = trade.is_fair() trade.save() return Response(trade_serializer.validated_data, status=status.HTTP_200_OK) return Response(None, status=status.HTTP_400_BAD_REQUEST)