如何删除或更新有TypeError的对象?

2024-10-03 09:17:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我的应用程序创建了一个有错误的对象,用户插入了一个字符串(我相信),但字段是十进制的。你知道吗

我知道表单会阻止它,但是插入发生在post\u save decorator上,现在我无法访问对象、更新或删除它。你知道吗

comandas_antecipadas = ComandaAntecipado.objects.all()
comandas_antecipadas
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "C:\projetos\barzim\venv\lib\site-packages\django\db\models\query.py", line 244, in __repr__
    data = list(self[:REPR_OUTPUT_SIZE + 1])
  File "C:\projetos\barzim\venv\lib\site-packages\django\db\models\query.py", line 268, in __iter__
    self._fetch_all()
  File "C:\projetos\barzim\venv\lib\site-packages\django\db\models\query.py", line 1186, in _fetch_all
    self._result_cache = list(self._iterable_class(self))
  File "C:\projetos\barzim\venv\lib\site-packages\django\db\models\query.py", line 63, in __iter__
    for row in compiler.results_iter(results):
  File "C:\projetos\barzim\venv\lib\site-packages\django\db\models\sql\compiler.py", line 1009, in apply_converters
    value = converter(value, expression, connection)
  File "C:\projetos\barzim\venv\lib\site-packages\django\db\backends\sqlite3\operations.py", line 254, in converter
    return create_decimal(value).quantize(quantize_value, context=expression.output_field.context)
TypeError: argument must be int or float

comandas_antecipadas.count()
11
comandas_antecipadas[9]
<ComandaAntecipado: ComandaAntecipado object (120)>
comandas_antecipadas[10]
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "C:\projetos\barzim\venv\lib\site-packages\django\db\models\query.py", line 302, in __getitem__
    qs._fetch_all()
  File "C:\projetos\barzim\venv\lib\site-packages\django\db\models\query.py", line 1186, in _fetch_all
    self._result_cache = list(self._iterable_class(self))
  File "C:\projetos\barzim\venv\lib\site-packages\django\db\models\query.py", line 63, in __iter__
    for row in compiler.results_iter(results):
  File "C:\projetos\barzim\venv\lib\site-packages\django\db\models\sql\compiler.py", line 1009, in apply_converters
    value = converter(value, expression, connection)
  File "C:\projetos\barzim\venv\lib\site-packages\django\db\backends\sqlite3\operations.py", line 254, in converter
    return create_decimal(value).quantize(quantize_value, context=expression.output_field.context)
TypeError: argument must be int or float


Tags: djangoinpyselfdbvenvvaluemodels
1条回答
网友
1楼 · 发布于 2024-10-03 09:17:15

当您试图在控制台中显示对象时,问题就出现了。所以,别那么做。直接删除即可:

comandas_antecipadas = ComandaAntecipado.objects.all()
comandas_antecipadas[9].delete()

相关问题 更多 >