Django许多插入订单 [英] Django Many To Many Insert Ordering

查看:114
本文介绍了Django许多插入订单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们一直在努力这几天,并在网络上进行了大量搜索。

We have been struggling with this for a few days and have done lots of searches on the web.

我们正在设法弄清楚条目如何保存在Django中许多领域的形式。

We are trying to figure out how entries are saved in Django forms for many to many fields.

例如,我们有一个与图像有很多关系的新闻模型。当我们向新闻文章添加图像时图片ID为10,2,14,我们可以看到保存新闻文章表单时的帖子值如下:

For example we have a news model that has a many to many relationship with images. When we add images to a news article e.g. images with id 10,2,14 we can see the post values are the following when saving a news article form:


  • 照片10

  • 照片2

  • 照片14

当我们看在多对多交叉表中,订单尚未保留。

When we look in the many to many intersection table the order has not been preserved. We can see no logic in the order the photos are inserted.

希望这是有道理的!

非常感谢为您的答案提前。

Many thanks for your answers in advance.

Arif

推荐答案

Django doesn'保证保持多对多关系的顺序。如果需要,您应该使用 通过 表,并显式显示订单字段。

Django doesn't guarantee to preserve the order of many-to-many relationships. If you need this, you should use a through table with an explicit 'order' field.

这篇关于Django许多插入订单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆