小编Mic*_*lov的帖子

无法为映射表组装任何主键列

当我尝试创建数据库模式迁移时,我遇到了这个奇怪的错误.你能帮我弄清楚出了什么问题吗?

$ python app.py db upgrade
[skipped]
sqlalchemy.exc.ArgumentError: Mapper Mapper|EssayStateAssociations|essay_associations could not assemble any primary key columns for mapped table 'essay_associations'
Run Code Online (Sandbox Code Playgroud)

我的模特:

class EssayStateAssociations(db.Model):
    __tablename__ = 'essay_associations'

    application_essay_id = db.Column(
        db.Integer,
        db.ForeignKey("application_essay.id"),
        primary_key=True),
    theme_essay_id = db.Column(
        db.Integer,
        db.ForeignKey("theme_essay.id"),
        primary_key=True),
    state = db.Column(db.String, default="pending")
Run Code Online (Sandbox Code Playgroud)

python sqlalchemy flask-sqlalchemy flask-migrate

35
推荐指数
3
解决办法
3万
查看次数

使用Rails进行条件渲染取决于环境

是否有适当的方法来检测应用程序布局中的环境(开发或生产)?说,我不想在我的本地沙箱中呈现GA代码.

在Django我们使用{% if not debug %}{% include '_ga.html' %}{% endif %}.我应该在Rails中使用什么?谢谢.

ruby-on-rails view ruby-on-rails-3

13
推荐指数
1
解决办法
2869
查看次数

Swift Beta 5中的字符串到浮点转换

以下代码在Beta 5中不再起作用.

let device = UIDevice.currentDevice()
if (device.systemVersion.bridgeToObjectiveC().floatValue < 8.0) {
    [skipped]
}    
Run Code Online (Sandbox Code Playgroud)

此外,不可能将字符串向下转换为浮动.

let device = UIDevice.currentDevice()
let version: Float = device.systemVersion as Float
Run Code Online (Sandbox Code Playgroud)

上面的代码段会返回'String' is not convertible to 'Float'错误.

任何想法我们现在应该如何测试操作系统版本?谢谢.

xcode ios swift

8
推荐指数
1
解决办法
4644
查看次数

修复无效的JSON转义

KISSmetrics生成我需要解析的无效JSON字符串.我遇到了很多错误

ERROR 2013-03-04 04:31:12,253 Invalid \escape: line 1 column 132 (char 132): {"search engine":"Google","_n":"search engine hit","_p":"z392cpdpnm6silblq5mac8kiugq=","search terms":"happy new year animation 1920\303\2271080 hd","_t":1356390128}

ERROR 2013-03-04 04:34:19,153 Invalid \escape: line 1 column 101 (char 101): {"search engine":"Google","_n":"ad campaign hit","_p":"byskpczsw6sorbmzqi0tk1uimgw=","search terms":"\331\203\330\261\330\252\331\207 \331\201\331\212\330\257\331\212\330\244\331\211 \330\256\331\212\331\204\330\247\330\255\331\211 \331\203\331\210\330\261\330\257\331\211","_t":1356483052}
Run Code Online (Sandbox Code Playgroud)

我的代码是:

for line in lines:
    try:
        data = self.clean_data(json.loads(line))
        except ValueError, e:
            logger.error('%s: %s' % (e.message, line))
Run Code Online (Sandbox Code Playgroud)

示例原始数据:

{"search engine":"Google","_n":"search engine hit","_p":"kvceh84hzbhywcnlivv+hdztizw=","search terms":"military sound effects programs","_t":1356034177}
Run Code Online (Sandbox Code Playgroud)

有没有机会清理这个凌乱的JSON并解析它?谢谢你的帮助.

python string parsing json

6
推荐指数
1
解决办法
1万
查看次数

计算 iPhone 移动的短垂直距离

目前我正在开发一个应用程序,它需要检测 iPhone 是否开始和停止垂直移动。我需要能够检测到非常短(50-100 厘米)的垂直距离,即一个人是否进行深蹲。

有没有办法计算Core Motion 框架

let motion = CMMotionManager()

if motion.isDeviceMotionAvailable {
    self.motion.deviceMotionUpdateInterval = 1.0 / 60.0
    self.motion.showsDeviceMovementDisplay = true

    self.motion.startDeviceMotionUpdates(using: .xMagneticNorthZVertical, to: .main, withHandler: { (data, error) in
        if let validData = data {
            // Just a random minimum acceleration threshold                    
            if validData.userAcceleration.y > 3 {
               print(validData.userAcceleration.y)
            }
         }
     })
}
Run Code Online (Sandbox Code Playgroud)

iphone cocoa-touch ios core-motion swift

5
推荐指数
1
解决办法
489
查看次数

为OS X创建交互式通知

Mac基础知识:通知会通知您,可以使用文本输入字段创建交互式警报:

例如,您可以直接通过通知回复聊天.

OS X聊天提醒

我该如何实现它?例如,我有一个通知:

let notification = NSUserNotification.init()
notification.hasActionButton = true
notification.actionButtonTitle = "Agree"
notification.title = "Header"
notification.informativeText = "Text."

NSUserNotificationCenter.default.deliver(notification)
Run Code Online (Sandbox Code Playgroud)

macos notifications nsusernotification swift swift3

3
推荐指数
1
解决办法
2316
查看次数