小编tre*_*dez的帖子

Django:如何在注释查询集中添加比较条件

我想在注释查询集中添加比较操作来计算特定字段的值。我怎样才能做到这一点?这是我的注释查询集

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)

我上面查询集的条件表达式运行错误。请帮我修好吗?

python django python-3.x

6
推荐指数
2
解决办法
2508
查看次数

如何在 Visual Studio Code 中运行调试 Django 应用程序?

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 中的断点。我怎样才能做到这一点?

python django python-3.x visual-studio-code

4
推荐指数
1
解决办法
3557
查看次数

标签 统计

django ×2

python ×2

python-3.x ×2

visual-studio-code ×1