如何在管理模型的保存方法中使用select_reded
我想从不同模型中获取特定信息,因此我使用select_reced的方法获取数据,但我无法将记录保存到db中。 如何在保存方法中使用select_reced?
假设我有以下模型 models.py.py
现在我想从StockList中获得product_quantity shipping_qty(来自库存型号)以获取剩余的最终数量。
admin.py ,
但是当我使用时,我无法将值保存/更新为db select_reced以获取特定信息。我该怎么做?谢谢。
I would like to get the specific information from different model therefore I have use the method of select_related to fetch the data but I unable to save the record into db.
How to use select_related in save method?
Let say I have following models
models.py
Now I would like to get the product_quantity from stocklist and do a subtraction between product_quantity and shipping_qty(from stockOut models) to get the final quantity that remain.
But I unable to save/update the value into db when I use the method of select_related to get the specific information. How would I go about doing this? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,如果您执行
stockout.object.all()。select_reled(“ shipts _qty”)
,您将不仅获得shipping_qty
和库存您想要的是,仅获取这些值
first of all you don't get only
shipping_qty
if you dostockOut.objects.all().select_related("shipping_qty")
but you get all stockOut instances with their shipping_qty and stockswhat you want is, to get these values for only the current instance