F
F
ffpenski2017-05-26 10:56:52
Django
ffpenski, 2017-05-26 10:56:52

What is the best way to create site versions for different cities in Django?

I want to create versions of the site for different cities in Django, but in fact all the processes in different cities will be the same, except for the names of the objects. It is necessary that when moving from the city page to any other page of the site, the user can return back to the page of the same city by clicking on the Logo (Of course, when changing the city, the return should occur to the page of another city)
From the implementation options I consider
1) create an app for each city
2) implement through sessions in one app
I already tried the second point, but there was a problem - the URL (located in base.html), which is activated when clicking on the Logo, is tied to the template-tag of the session with the city variable. On the city page, the link with the Logo works, but when you go to any other page, the link stops working ...
I would also like to hear other possible implementation options)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anatoly Scherbakov, 2017-05-26
@ffpenski

Make an app for each city and copy all the code, given that it is the same? it makes no sense.
It is better to consider the problem differently. Let's start with registered users. Create a City model representing the city. Also create a custom user profile model called, say, Profile , which is bound to User in a one to one relationship. In the Profile model, add a foreign key on City .
Finally implement:
If city support is also needed for anonymous users (most likely it is), then it is worth using the session variable as an additional layer. In one of my projects I do it like this:
Thus, anonymous are also supported, and when a session is reset, a registered user does not lose the selected option.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question