[Django]-How to show content depending on domain/subdomain

2๐Ÿ‘

โœ…

I think you should have a look at the django.contrib.sites models, which are there for precisely the problem you are trying to solve โ€“ have multiple subdomain and domain represented by the content.

Quoting the example mentioned there:

from django.db import models
from django.contrib.sites.models import Site

class BlogEntry(models.Model):
    headline = models.CharField(max_length=200)
    text = models.TextField()
    # ...
    sites = models.ManyToManyField(Site)
๐Ÿ‘คAnshul Goyal

1๐Ÿ‘

From a DB design standpoint you should move the lang field to an own model and reference it from the BlogEntry.

class Language(models.Model):
    lang = models.CharField(max_length="2")

class BlogEntry(models.Model):
    text = models.TextField()
    lang = manufacturer = models.ForeignKey('Language')

That way you can change the actual name of the language by updating a single record and not multiple. However, if you are sure that this will never you can also stick with your approach.

๐Ÿ‘คMartin Thurau

Leave a comment