On Wed, 20 Apr 2022, 11:05 Kasper Laudrup, <[email protected]> wrote:

> On 20/04/2022 11.33, Ankit Chaurasia wrote:
> > from django.db import models
> > class Customer(models.Model):
> >      name = models.CharField(max_length=20)
> >      phone = models.IntegerField()
> > I want to concatenate name + last digit of phone number.
> >
>
> It makes no sense to store a phone number as an integer. A phone number
> is not something you can increment, decrement or do similar arithmetic
> operations with.
>

Not only that, but it is all too easy to lose the leading zeroes that are
often part of a phone number. Kasper is right: don't go there. (I won't
even mention about leading plus signs...)


> Just use a CharField or probably even better, a field dedicated to phone
> numbers:
>
> https://pypi.org/project/django-phonenumber-field/
>
> Using a more proper field type will make it simple to do the
> concatenation using standard Python.
>
> Kind regards,
>
> Kasper Laudrup
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/789404f7-e665-d102-1dee-406cbfcfe4cd%40stacktrace.dk
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAHAc2jdzq8qvP47BfxgDbRJ25qAM4cqBvqPhmFZWvvZM3-rqzw%40mail.gmail.com.

Reply via email to