When storing phone numbers in Django, should I store them as raw numbers or use django.contrib.localflavor?

The name could be confusing, but please let me explain:

I am currently storing a phone number with raw digits, for example 5554441234. Then in my template I was going to "format" the number into something like 555-444-1234.

I realized in Django localflavor, there is a US phone field number that checks if the string is in format XXX-XXX-XXXX.

So my question is: should I enter the phone number as raw digits, then format it in the template or enter the phone number in a formatted way using localflavor ?

If I choose the latter, will the format restriction XXX-XXX-XXXXeven apply to the level database APIor on the Django admin page?

+5
source share
3 answers

Save them as entered, if necessary, separate them with a space. The way the user formats his number, stores semantic information that you do not want to lose by normalizing it. In the USA, the format is XXX-XXX-XXXXvery common, but other locales use completely different formats. For example, where I live, some common formats: XX-XXX XXX XX, XXX/XXX XX XX, +46(0)70-XXX XX XXetc. Ad nausem.

, , , , , , , . . : http://discuss.fogcreek.com/dotnetquestions/default.asp?cmd=show&ixPost=6079&ixReplies=6

+9

(, Django), . , , XXX-XXX-XXXX.

CharField, .

+2

Django-phoneno. . - Python.  pip install django-phonenumber-field

https://pypi.python.org/pypi/django-phonenumber-field/0.2a3

0

All Articles