问题标签 [django-3.2]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
django - 带有实例字段值的 DJango 复合主键
嗨,我在 django 3.2 中遇到了复合键的工作问题。根据我的客户要求,他需要一个复合键作为主键,而不仅仅是在 unique_together 约束上,所以我想知道是否有任何方法或地方可以在验证之前拦截实例并用来自其他字段的值填充复合键并将其保存到数据库ej:
在这些行中,我无法从 django 管理站点上的表单字段验证器中获得通过,所以我真的无法测试信号或 save() 方法,任何帮助都将不胜感激。
django - 调整和转换 mime 图像 Django
我在保存图像之前尝试调整大小并转换 mime
模型.py
函数upload_to_path and image_manipulation
已导入from utils.utils import upload_to_path, image_manipulation
实用程序/utils.py
使用此代码工作,但我没有实现此代码以转换为png
...
当我尝试类似:
当我进行此更改时,文件被上传、调整大小和转换,但初始文件(jpg
)也被上传。如果可能的话,我很感激如果我能解释一下这个过程的流程,在一个可调用的那个,接收方法本身的upload_to
2 个参数之间,因为从我的 pov 来看是关于数据库中的记录,并且是关于文件系统存储......(instance, filename)
save()
upload_to
save()
你能看到吗,我很困惑
django - Update date and name field of model based on the field of another model
I am a bit stuck... I am building a bookkeeping system as a practice for me to learn django more
I have a model for Bank as below:
I then have an Income sheet statement like below
My wish is that, when I enter an invoice in the Income sheet I can be able to select the same invoice number from Bank model and when I enter the payment date of that invoice it must update the Income sheet automatically
TIA!!!
django - Django 复杂关联注释,包括计数和总和
我有以下 Django 查询:
它本质上通过“ticket_owner_email_address”查找特定模型(预订)。对于每个“ ticket_owner_email_address
”,我想在 Booking 上进行查找,但返回字段“some_field”和“some_other_field”。对于多个预订,这两个字段可以相同。
当我在做计数和求和时,如果我尝试将这两个值添加到列表中,它们要么是空的,要么会破坏计数/求和命令。
我想知道,插入这些关联值的最佳查询表达式方法是ticket_owner_email_address
什么?我尝试了一个带有 OuterRef 的子查询,但不幸的是这似乎不起作用(我基本上没有正确设置它)。
任何专业的 Django ORM 技巧将不胜感激!
python-3.x - 将 django 中的 URL 路径名更改为简单字符串而不是所有 id
在 Django 3.2.8 中,我有一个视图,它生成一个 CSV 文件,其中包含来自多个数据库实例的信息。CSV 是从项目页面中的按钮生成的。
我想知道是否有办法将 URL 更改为类似
导出/csv/all_items
而不是这样的:
导出/csv/1,2,3,4,5
其中 1,2,3,4,5 是导出实例的 ids/pk
在 urls.py 我添加:
其中,itemIds是从视图export_csv中触发的视图项目中收集的 pk/id列表生成的字符串。
视图.py
提前致谢
pytest - Django AttributeError:“函数”对象没有“包装”属性
我在使用 pytest 运行 Django 测试时遇到了这个错误。测试完成时发生错误。我在用
Django==3.2.12
pytest==7.0.1
pytest-django==4.3.0