python - 类型错误 : __init__() got an unexpected keyword argument 'decimal_places'

标签 python django django-models

我在 models.py 中定义了这个模型:

class FarmAnalytics(models.Model):
    water_saved = models.FloatField(default=0, decimal_places=2)
    last_full_execution = models.DateField(auto_now=False, auto_now_add=False)
    current_state = models.CharField(max_length=50) #watering/calculating/resting

而且,我得到以下错误:

    Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
    utility.execute()
  File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 312, in execute
    django.setup()
  File "/Library/Python/2.7/site-packages/django/__init__.py", line 18, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/Library/Python/2.7/site-packages/django/apps/registry.py", line 108, in populate
    app_config.import_models(all_models)
  File "/Library/Python/2.7/site-packages/django/apps/config.py", line 198, in import_models
    self.models_module = import_module(models_module_name)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/Users/krishna/Documents/temp/tutorial/quickstart/models.py", line 10, in <module>
    class FarmAnalytics(models.Model):
  File "/Users/krishna/Documents/temp/tutorial/quickstart/models.py", line 11, in FarmAnalytics
    water_saved = models.FloatField(default = 0, decimal_places = 2)
TypeError: __init__() got an unexpected keyword argument 'decimal_places'

我不知道我做错了什么,我是 django 的新手,今天才开始使用它。

最佳答案

字段类型FloatField 不接受decimal_places 作为选项,它是DecimalField 的选项。 .如果适合您的需要,您可以尝试将 FloatField 更改为 DecimalField。

关于python - 类型错误 : __init__() got an unexpected keyword argument 'decimal_places' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33380116/

相关文章:

python - 重复列值及其对应的非重复列的解决方案

python - 使用O(1)空间在python中自下而上的斐波那契

python unhexlify 未按预期工作

django - 插入 Django 模板包含变量

Django - 如何将 ImageField 文件存储在不同的文件夹中?

Django:如何将sql语句插入sqlite3数据库并配置模型

python - 一个音符的录制音频会产生多个起始时间

python - Django -- manage.py shell 不适用于 git bash 终端

python - 以字符串形式返回模板 - Django

python - 覆盖 Django 中的保存导致无限递归错误