所以这发生在我身上:
thing = ModelClass()
thing.foo = bar()
thing.do_Stuff()
thing.save() #works fine
thing.decimal_field = decimal_value
thing.save() #error here
追溯如下:
TypeError at /journey/collaborators/2/
unsupported operand type(s) for ** or pow(): 'Decimal' and 'str'
274. oH.save()
File "/usr/lib/python2.7/dist-packages/django/db/models/base.py" in save
460. self.save_base(using=using, force_insert=force_insert, force_update=force_update)
File "/usr/lib/python2.7/dist-packages/django/db/models/base.py" in save_base
543. for f in meta.local_fields if not isinstance(f, AutoField)]
File "/usr/lib/python2.7/dist-packages/django/db/models/fields/subclassing.py" in inner
28. return func(*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/django/db/models/fields/__init__.py" in get_db_prep_save
787. self.max_digits, self.decimal_places)
File "/usr/lib/python2.7/dist-packages/django/db/backends/__init__.py" in value_to_db_decimal
705. return util.format_number(value, max_digits, decimal_places)
File "/usr/lib/python2.7/dist-packages/django/db/backends/util.py" in format_number
145. return u'%s' % str(value.quantize(decimal.Decimal(".1") ** decimal_places, context=context))
我尝试设置decimal_value
为一个decimal.Decimal
实例、一个浮点数、一个 int 和一个字符串。除非我将该字段留空,否则我似乎无法保存我的模型实例。
任何想法如何解决这一问题?