一つは以下の通りです:私は通常私のモデルを使用すると、すべてが正常であるDjango "DecimalFieldsは 'decimal_places'属性を定義する必要があります。"私のモデルフィールドの
aaf_1kg_all = models.DecimalField(blank=True, null=True)
。私はready()
hookでそれを使用する場合は、しかし、私はこのエラーを取得する:
SystemCheckError: System check identified some issues:
ERRORS:
myapp.Model.aaf_1kg_all: (fields.E130) DecimalFields must define a 'decimal_places' attribute.
myapp.Model.aaf_1kg_all: (fields.E132) DecimalFields must define a 'max_digits' attribute.
Djangoのドキュメントは、これら二つの属性がオプションであることを言います。私はthis answerを見ましたが、データベースでは小数点とmax_digitsが両方とも定義されています。
私はこれらの属性を追加することを決定した場合、すなわち
aaf_1kg_all = models.DecimalField(blank=True, null=True, max_digits=10, decimal_places=10)
アプリを実行すると、私は代わりに、このエラーを取得するいくつかの点で:
Traceback (most recent call last):
[...]
variants.extend(list(sub_qs)) # sub_qs is a QuerySet
File ".../django/db/models/query.py", line 258, in __iter__
self._fetch_all()
File ".../django/db/models/query.py", line 1074, in _fetch_all
self._result_cache = list(self.iterator())
File ".../django/db/models/query.py", line 68, in __iter__
for row in compiler.results_iter(results):
File ".../django/db/models/sql/compiler.py", line 808, in results_iter
row = self.apply_converters(row, converters)
File ".../django/db/models/sql/compiler.py", line 792, in apply_converters
value = converter(value, expression, self.connection, self.query.context)
File ".../django/db/backends/sqlite3/operations.py", line 233, in convert_decimalfield_value
value = expression.output_field.format_number(value)
File ".../django/db/models/fields/__init__.py", line 1608, in format_number
return utils.format_number(value, self.max_digits, self.decimal_places)
File ".../django/db/backends/utils.py", line 200, in format_number
value = value.quantize(decimal.Decimal(".1") ** decimal_places, context=context)
decimal.InvalidOperation: [<class 'decimal.InvalidOperation'>]
私は何かを忘れてしまいましたか?
'max_digits'と' decimal_places'引数[フォームフィールド]のためのオプションである(https://docs.djangoproject.com/en/1.9/ref/forms/fields/#decimalfield )。これらは[モデルフィールド](https://docs.djangoproject.com/ja/1.9/ref/models/fields/#decimalfield)に必要です。 – Alasdair
このリンクhttp://stackoverflow.com/questions/33827179/python-decimal-invalidoperation-errorはあなたのエラーを解決するのに役立ちます –
私はdownvotesを理解していませんが、答えを得ることはすべて重要です。ありがとう。 – JulienD