django - Django 查询错误:int() 参数必须是字符串、类似字节的对象或数字,而不是 'datetime.timedelta'
问题描述
我要记录哪个人的寿命不到 1 个月。
cnt = Personne.objects.annotate(
duration=Func(Func(F('deces_an_grg'), F('deces_mois_grg'), F('deces_jour_grg'), function='make_date'), Func(F('date_declaration_an_grg'), F('date_declaration_mois_grg'), F('date_declaration_jour_grg'), function='make_date'), function='age')
).filter(duration__gt=timedelta(days=30)).count()
但它会发生这样的错误。什么原因?我该如何解决?
int() argument must be a string, a bytes-like object or a number, not 'datetime.timedelta'
Request Method: GET
Request URL: ....
Django Version: 1.10
Exception Type: TypeError
Exception Value:
int() argument must be a string, a bytes-like object or a number, not 'datetime.timedelta'
Exception Location: /***/venv/lib/python3.7/site-packages/django/db/models/fields/__init__.py in get_prep_value, line 1832
Python Executable: /***/venv/bin/python
Python Version: 3.7.1
Python Path:
['***',
'/***/venv/lib/python37.zip',
'/***/venv/lib/python3.7',
'/***/venv/lib/python3.7/lib-dynload',
'/usr/local/Cellar/python/3.7.1/Frameworks/Python.framework/Versions/3.7/lib/python3.7',
'/***/venv/lib/python3.7/site-packages']
解决方案
推荐阅读
- javascript - 将不同的样式应用于引导卡
- c# - Entity Framework Core OwnsOne 创建单独的表而不是同一表中的属性
- python - 在 nx nCr 矩阵中找到上三角形
- excel - 将值粘贴到多列中的 VBA 代码
- reactjs - 如何通过使用 react 和 typescript 输入 url 来限制用户访问特定页面?
- c - 使用malloc初始化char *后如何获取char *指向的连续内存长度?
- php - 带有连接和值的 SQL 插入
- c# - 列表仅返回第一个值
- c# - C# 单元测试复杂的多线程数据库读取
- ethereum - web3 发送数据和令牌