Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django storing mobile number, what field to use?

In my models I need to store a mobile number in the following format 447182716281. What field should I use? Does Django have anything to support this?

example

 mobile = models.IntegerField(max_length=12)
like image 233
MarkO Avatar asked Mar 17 '13 19:03

MarkO


2 Answers

I think is a interesting question since it really depends on the problem modeling, CharField works fine, but have a look at this:

ORM tricks

like image 93
PepperoniPizza Avatar answered Oct 07 '22 02:10

PepperoniPizza


On using models.IntegerField(default=0) for larger number it gives error Ensure this value is less than or equal to 2147483647.

So better way to use would be. BigIntegerField A 64-bit integer, much like an IntegerField except that it is guaranteed to fit numbers from -9223372036854775808 to 9223372036854775807. The default form widget for this field is a TextInput.

like image 43
Nitish Kumar Pal Avatar answered Oct 07 '22 02:10

Nitish Kumar Pal