如何枚举新列? [英] How to enumerate new column?

查看:55
本文介绍了如何枚举新列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Django管理员中,我有一个 TabularInLine 类.在图片中,此类的每个元素都用其自己的 ID 进行编号.该 TabularInLine 类具有另一个类(类 Part )的外键.我怎样才能为每个 FK 的编号( my_id )从1开始编号,如下图所示?

In my Django admin I have a TabularInLine class. In the picture, each element of this class is numbered with it's own ID. This TabularInLine class has a foreign key to an other class (class Part). How I can to numerate that for each FK with the numbering (my_id) started from 1 as in the picture below?

推荐答案

,您可以定义自己的 insert 操作,该操作将执行以下步骤:

you can define your own insert operation which does those steps:

  • 使用新条目的外键查询数据库
  • 获取结果计数
  • 分配my_id = count + 1

假设您的数据库中已经有该表.您要向数据库添加一个新条目,该条目具有 FK ="three" .

let's say you already have that table in your database. you want to add a new entry to database, which has FK="three".

  • 查询数据库中的对象( FK ="three" ).
  • 结果数为2.(最后两行)
  • 分配my_id = 3

这篇关于如何枚举新列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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