编辑值时出现Django EncryptedCharField错误

编辑值时出现Django EncryptedCharField错误,django,encryption,pycrypto,django-extensions,Django,Encryption,Pycrypto,Django Extensions,这是给我的Django同志们的 我试图在Django 1.6.5和MySQL中构建一个应用程序,其中一些数据库字段被加密,以尊重用户的隐私。我已经成功地安装了django扩展,并成功地使用EncryptedCharField进行了简单的保存和数据检索 但是,在使用EncryptedCharField进行浮点运算时,我遇到了一个问题。现在,简单的类型转换很有用。这个问题似乎不是那个问题。我试图从一个加密字段开始,该字段是一个值,通过加/减一些数字来更改该值,然后将其保存回数据库。我已经设法减少并重

这是给我的Django同志们的

我试图在Django 1.6.5和MySQL中构建一个应用程序,其中一些数据库字段被加密,以尊重用户的隐私。我已经成功地安装了django扩展,并成功地使用EncryptedCharField进行了简单的保存和数据检索

但是,在使用EncryptedCharField进行浮点运算时,我遇到了一个问题。现在,简单的类型转换很有用。这个问题似乎不是那个问题。我试图从一个加密字段开始,该字段是一个值,通过加/减一些数字来更改该值,然后将其保存回数据库。我已经设法减少并重现了如下错误:

>>> user_id = 1
>>> account = AccountCash.objects.get( id = 1 )
>>> account.id
1L
>>> account.portfolio_id
1L
>>> account.account_name
u'My Cash'
>>> account.current_value
u'200'
>>> account.current_value = account.current_value - 10
Traceback (most recent call last):
  File "<console>", line 1, in <module>
TypeError: unsupported operand type(s) for -: 'unicode' and 'int'
        # Make the new account, passing in the portfolio it belongs to
        new_account = AccountCash(
            portfolio                   = portfolio,
            account_name                = newCashAccountForm.cleaned_data['account_name'],
            starting_balance            = newCashAccountForm.cleaned_data['starting_balance'],
            current_value               = newCashAccountForm.cleaned_data['starting_balance'],
        )
        new_account.save()
我一直无法找出将浮点值分配给加密字段与我最初设置值的地方有什么不同:

>>> user_id = 1
>>> account = AccountCash.objects.get( id = 1 )
>>> account.id
1L
>>> account.portfolio_id
1L
>>> account.account_name
u'My Cash'
>>> account.current_value
u'200'
>>> account.current_value = account.current_value - 10
Traceback (most recent call last):
  File "<console>", line 1, in <module>
TypeError: unsupported operand type(s) for -: 'unicode' and 'int'
        # Make the new account, passing in the portfolio it belongs to
        new_account = AccountCash(
            portfolio                   = portfolio,
            account_name                = newCashAccountForm.cleaned_data['account_name'],
            starting_balance            = newCashAccountForm.cleaned_data['starting_balance'],
            current_value               = newCashAccountForm.cleaned_data['starting_balance'],
        )
        new_account.save()

我发现了这个问题:我需要像这样键入一个unicode:account.current_value=unicode floataccount.current_value-10提供完整的答案,或者删除对其他读者没有用处的问题。要么提供一些有用的信息,要么停止浏览我的帖子。我不是在浏览你的帖子,请阅读有关如何使用SO的指南。评论是针对这样的评论。它们不应用于回答问题;从这个意义上说,你是在自我推销。