我想在注释查询集中添加比较操作来计算特定字段的值。我怎样才能做到这一点?这是我的注释查询集
sale_item_list = OrderItem.objects.filter(order_id=order.id) \
.values('item__name') \
.annotate(price=F('price')) \
.annotate(exchange_rate=F('exchange_rate')) \
.annotate(quantity=F('quantity') \
.annotate(amount=Case(
When(F('quantity') < F('inventory'), then=Sum(F('quantity') * F('price'))),
When(F('quantity') > F('inventory'), then=Sum(F('inventory') * F('price'))),
output_field=IntegerField()))
Run Code Online (Sandbox Code Playgroud)
我上面查询集的条件表达式运行错误。请帮我修好吗?
launch.json
"name": "Django",
"type": "python",
"request": "launch",
"stopOnEntry": true,
"pythonPath": "${config.python.pythonPath}",
"program": "${workspaceRoot}/manage.py",
"cwd": "${workspaceRoot}",
"args": [
"runserver",
"--noreload"
],
"debugOptions": [
"WaitOnAbnormalExit",
"WaitOnNormalExit",
"RedirectOutput",
"DjangoDebugging"
]
Run Code Online (Sandbox Code Playgroud)
在浏览器中,http://localhost:8000/login我有一个登录页面,允许用户输入用户名和密码进行登录。我def login在views.py中的代码中放置了一个断点并运行调试,但执行并没有在有断点的行上停止。现在我想允许用户输入用户名和密码,然后他们点击按钮,它会跳转到def loginviews.py 中的断点。我怎样才能做到这一点?