Does PhoneNumberField for models exist?

2,309 views
Skip to first unread message

DragonSlayre

unread,
Jan 5, 2009, 5:33:11 PM1/5/09
to Django users
http://docs.djangoproject.com/en/dev/topics/forms/modelforms/

This lists PhoneNumberField as being a field type, but in the models
documentation, http://docs.djangoproject.com/en/dev/ref/models/fields/#ref-models-fields
there is no such field.

Does anybody know if this field exists? I'd quite like to use it.

Malcolm Tredinnick

unread,
Jan 5, 2009, 6:45:48 PM1/5/09
to django...@googlegroups.com

There's no phone number field for models. Just use a character field.

Regards,
Malcolm


Karen Tracey

unread,
Jan 5, 2009, 6:46:25 PM1/5/09
to django...@googlegroups.com

It's in the US localflavor, just as the associated formfield is:

http://docs.djangoproject.com/en/dev/ref/contrib/localflavor/#django.contrib.localflavor.us.models.PhoneNumberField

(Moving that and the US state field out of the general fields and into the appropriate localflavor looks to have been a fairly late fixup for 1.0, which is probably why mention of it is leftover in the general docs.)

Karen

DragonSlayre

unread,
Jan 5, 2009, 6:49:32 PM1/5/09
to Django users
Thanks :)

On Jan 6, 12:46 pm, "Karen Tracey" <kmtra...@gmail.com> wrote:
> On Mon, Jan 5, 2009 at 5:33 PM, DragonSlayre <LSSay...@gmail.com> wrote:
>
> >http://docs.djangoproject.com/en/dev/topics/forms/modelforms/
>
> > This lists PhoneNumberField as being a field type, but in the models
> > documentation,
> >http://docs.djangoproject.com/en/dev/ref/models/fields/#ref-models-fi...
> > there is no such field.
>
> > Does anybody know if this field exists? I'd quite like to use it.
>
> It's in the US localflavor, just as the associated formfield is:
>
> http://docs.djangoproject.com/en/dev/ref/contrib/localflavor/#django....

Malcolm Tredinnick

unread,
Jan 5, 2009, 6:54:37 PM1/5/09
to django...@googlegroups.com

Sorry, I hit "send" before finishing my post. There's much more to it
than this:

The model field PhoneNumberField is an historical holdover from the days
when Django supported the entire world as known to people in Kansas --
the USA (yes, I'm joking. They also knew Canada existed because they
liked music and ... hey... Celine Dion and Bryan Adams! :-)). Since it's
release, it's become clear that there are countries outside the US and
they also have discovered this telephone-like device and have their own
numbering system. So whilst PhoneNumberField did exist at one point, it
was more trouble than it was worth, as it only supported North American
style phone numbers. Thus, it has been moved to
django.contrib.localflavor.us.

Long-term, we don't really need a special phone number field, since it
is just a text field. Probably with some validation rules, but since we
don't have model-level validation in Django 1.0, that's a moot point.
Adding an appropriate phone number validator to a text field will be
easy in Django 1.1 (or whenever model-level validation lands).

At the *form* level, however, we have 473 different phone number fields,
it seems. Many of the django.contrib.localflavor.* packages contain some
kind of phone number validation and one day, in the distant future,
making things less messy there is something I'm going to take a week to
do.

The reason for the extra form-level fields is that forms do validation
and data normalisation, which models don't do (at the moment, at least).
Thus there are lots of formats handled for the data input. By the time
it gets to the model to be stored in the database, things are much more
uniform: a string of digits and, possibly, letters.

Hopefully that explains some of the background and helps understand
what's going on a bit beyond the documentation.

You've kind of identified that we do need to fix that table a little
bit, however. Removing things that don't exist any longer.

Regards,
Malcolm

Reply all
Reply to author
Forward
0 new messages