I came today with a design / architecture question regarding Django.
I work on several websites (hosted on the same server) that individually need geographic data (states, cities, etc.). Each project contains applications, and each application can contain models with fields ForeignKeyfor a city or state.
In order not to repeat myself, I cannot create a database to store these cities and states and use it through Django projects .
Django provides an easy way to use multiple databases in one project by declaring it in a file settings.pyand writing classes of routers to store data for reading and writing. But in this way it is impossible to use an operator select_related, for example:
job = get_object_or_404(Jobs.objects.select_related('state__town'), user=user)
This behavior is just natural for me (it is impossible to create connections between databases, from scratch) ...
My questions:
- It is a good idea to consider introducing dblinks (I don’t think so ...) and can Django handle it (I have not found any documents for this part)?
- What will you do when faced with such a situation?
A quick and dirty solution is to import all geodata (cities, states ...) into each project database, but not DRY at all :(:
python manage.py loaddata geo.json
"geo", "" ( , ) ... , GeoDjango, , , , !
!