I
I
Ilya Lopuga2021-02-17 15:32:21
Django
Ilya Lopuga, 2021-02-17 15:32:21

How to store (and search) cities in different languages ​​in django?

It is required to store in the base of the city (whether there will be a link to the country is still unknown, the city is actually important). You need to store in Russian and English (and in the future also in others). How to implement storage so that it is possible to find a city by name in any language?

One option comes to mind:

class City(models.Model):
    lat = models.FloatField()
    lon = models.FloatField()
    
    
class CityName(models.Model):
    city = models.ForeignKey('City', on_delete=models.CASCADE),
    name = models.CharField(max_length=128)
    lanuage = models.CharField(max_length=8)


we can filter CityName and use it to give the ID of the city (which will be tied to the user later).
how correct is it? Does anyone have any ideas on how to implement this more beautifully?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question