如何存储由django中的零引用的整数 [英] How to store an integer leaded by zeros in django

查看:115
本文介绍了如何存储由django中的零引用的整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在django中存储一个如下所示的数字:

  000001 
解决方案

不要将它存储在前导零中。在输出上格式化:

 (视图中:value = 1)
{{value | stringformat:04d }}#显示为0001


I'm trying to store a number in django that looks like this:

000001

My problem is that if I type this inside an IntegerField it gets converted to "1" without the leading zeros. I've tried also with a DecimalField with the same result. How can I store the leading zeros whithout using a CharField? (I need to manipulate that number in it's integer form)

解决方案

Don't store it with the leading zeros. Format it on output instead:

(in view: value = 1)
{{ value|stringformat:"04d" }} # displays as 0001

这篇关于如何存储由django中的零引用的整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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