我对Django和dicts有意见。我只想得到符合如下刺痛的物品。但我不能让它工作。谢谢你的帮助。你知道吗
django_db_query = [{'time': '13:00 Uhr', 'titel': 'test1'}, {'time': '14:00 blah', 'titel': 'test2'}, {'time': '13:00 Uhr', 'titel': 'test3'},]
all_db_items = Django_db.objects.all()
only_13 = dict()
for item in all_db_items:
if item.time is "13":
only_13 += item
需要:数据结构和多个值从我的数据库在我的dict,但只与时间13:00 Uhr
for item in only_13:
print item.titel
console
test1
test2
假设你的djangdbmodel看起来像
在这种情况下你需要做的就是
DjangoDbModels.objects.filter(time__hour=13)
如果您只想拥有从第13小时开始的项目。例如,可以对日、年和月应用类似的过滤器。你知道吗is
仅适用于相同的操作数+
不是为dict实现的,请改用update
更多资源: https://www.python-course.eu/dictionaries.php
相关问题 更多 >
编程相关推荐