If the formatting of the phonograms does not change, you can write your own function for formatting the number of calls (see this ). A better approach would be to use a third-party library for this, like python-phonenumbers
. The easiest way is to do something like this:
import phonenumbers class Business(models.Model): phone = ... def formatted_phone(self, country=None): return phonenumbers.parse(self.phone, country)
in the template
Alternatively (or at the same time) write a custom template filter to format the caller's number. It will look like this:
{{ business.phone|phonenumber }} or {{ business.phone|phonenumber:"GB" }}
and it is written:
import phonenumbers @register.filter(name='phonenumber') def phonenumber(value, country=None): return phonenumbers.parse(value, country)
If you intend to use formatting in a template, write a template filter. If you think that you need formatting in other aspects of your application, for example, when listing names in the administrator, write it in the model (but lose the ability to pass parameters to the function)
source share