如何更改模型中字段的ID格式?

问题描述 投票:0回答:1

例如,我有一个customer [ID s from]字段

1, 2, 3, 4, 5, ...

但是我想将格式更改为

010101, 010102, 010103, 010104, 010105, ...

它显示在我的数据库和模板上。

有什么办法吗?

python django postgresql django-models pgadmin-4
1个回答
0
投票

您不能将前导0加到整数并存储在db中,您只能管理选择结果。例如

 select concat('0101', lpad(yourcol,2,'0') 
 from your table 
© www.soinside.com 2019 - 2024. All rights reserved.