How to alter data entered into django models to fit a criteria?

I have a django models.py file that I use to store information in my database. I store information on businesses and the countries that they operate in. I get the list of countries from their website. However they may call each country by a different name or use different formatting, for example 'The Gambia' vs 'Gambia', 'Eswatini' vs 'Swaziland', 'Trinidad and Tobago' vs 'Trinidad & Tobago'', 'The United States' vs 'United States of America'. I want that when I store the names of these countries in my database they automatically follow a set of rules to ensure consistent formatting of their names. Additionally, some websites state something like 'We operate in 150 countries'. I want to enter this information into the database but not have it come up when I request a list of countries from the frontend.

Here is my models.py:

class Company(models.Model): #the newly created database model and below are the fields

    name = models.CharField(max_length=250, blank=True, null=True) #textField used for larger strings, CharField, smaller
    slug = models.SlugField(max_length=250, blank=True, db_index=True, unique=True)
    
    
    available_merchant_countries = models.TextField(max_length=2500, blank=True, null=True)
    available_merchant_countries_source = models.URLField(max_length=250, blank=True, null=True)

    

Countries aren't stored one-at-a-time. I store a whole list of comma-separated countries at a time.

Вернуться на верх