I have a Django application that currently supports multiple languages. I would like to add support for subdomains so that “de.mysite.com” requests for German items and mysite.com in English (the default language). There will be about 20 subdomains pointing to the same Django application.
I have an abstract model with all fields for my data and a derived model for each language. Each language has its own database table, for example:
class ArticleBase(models.Model):
title = models.CharField(max_length=240, unique=True)
date_added = models.DateField(auto_now_add=True)
class Meta:
abstract = True
class Article(ArticleBase):
pass
class Article_de(ArticleBase):
pass
I can get articles like this (today it works for me):
def article(request, title, language=None):
if language:
mod = get_model('app', 'Article_' + language)
items = mod.filter(title=title)
else:
items = Article.objects.filter(title=title)
This is my current URL pattern:
url(r'^article/(?P<title>[a-zA-Z_-]+)/$", 'app.views.article', name='article'),
URL-, ? , ?