# Sites framework or custom model for multi-sites

**URL:** <https://forum.djangoproject.com/t/sites-framework-or-custom-model-for-multi-sites/10929>\
**Category:** Using Django\
**Created:** [December 10, 2021, 8:31am UTC](https://forum.djangoproject.com/t/sites-framework-or-custom-model-for-multi-sites/10929 "2021-12-10T08:31:21Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![anjanesh](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/anjanesh/32/4583_2.png) [@anjanesh](https://forum.djangoproject.com/u/anjanesh)\
**Post date:** [December 10, 2021, 8:31am UTC](https://forum.djangoproject.com/t/sites-framework-or-custom-model-for-multi-sites/10929/1 "2021-12-10T08:31:21Z")

</div>

I want to launch a Django 4 site with multiple domains linked to the same project.  
I created a model like this :

```auto
class Sites(models.Model):    
    domain = models.CharField(max_length=100)
    name = models.CharField(max_length=100)
    google_analytics_code = models.CharField(max_length=25)
    email = models.EmailField(max_length=100)
    created = models.DateTimeField(auto_now_add=True)
    active = models.BooleanField(default=True)

    def __str__ (self):
        return self.name

```

Then I came across the [Sites framework](https://docs.djangoproject.com/en/4.0/ref/contrib/sites/) in Django.

1. I think the Sites framework will do instead of creating a `class Sites(models.Model)` right ?
2. How do I enter a list of 20 domain names with some meta data like name etc to the project using the built-in Sites framework ?

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [December 10, 2021, 12:40pm UTC](https://forum.djangoproject.com/t/sites-framework-or-custom-model-for-multi-sites/10929/2 "2021-12-10T12:40:16Z")

</div>

When you say:

> [@anjanesh](#):
>
> I want to launch a Django 4 site with multiple domains linked to the same project.

Are you saying?

- You want one project, with one set of models, effectively serving the same content for multiple different domains

or

- You want one project, with some data and content the same, serving some identical content and some site-specific content.

or

- You want one installation of code, serving totally unique content for each domain.

My understanding of the sites framework is that it’s targeted at the second case. If I were faced with either the first or third case, I’d probably do something other than that.

---

<div class="post-metadata">

**Author:** ![anjanesh](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/anjanesh/32/4583_2.png) [@anjanesh](https://forum.djangoproject.com/u/anjanesh)\
**Post date:** [December 10, 2021, 12:45pm UTC](https://forum.djangoproject.com/t/sites-framework-or-custom-model-for-multi-sites/10929/3 "2021-12-10T12:45:49Z")

</div>

_You want one project, with one set of models, effectively serving the same content for multiple different domains_ - No.

_You want one installation of code, serving totally unique content for each domain_ - This is what I thought first but then I realized there may be some or very few overlapping content in more than one domain (site).

So basically #2. If I include `from django.contrib.sites.models import Site` will I be able to enter the data in the admin ? And how do I enter some extra site fields / columns ?

[https://docs.djangoproject.com/en/4.0/ref/contrib/sites/#associating-content-with-multiple-sites](https://docs.djangoproject.com/en/4.0/ref/contrib/sites/#associating-content-with-multiple-sites)

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [December 10, 2021, 12:57pm UTC](https://forum.djangoproject.com/t/sites-framework-or-custom-model-for-multi-sites/10929/4 "2021-12-10T12:57:54Z")

</div>

> [@anjanesh](#):
>
> If I include `from django.contrib.sites.models import Site` will I be able to enter the data in the admin ?

Yes. The module includes an admin.py file for adding Site model data.

> [@anjanesh](#):
>
> And how do I enter some extra site fields / columns ?

Create a model (perhaps named something like “SiteExtension”) with a One-to-One relationship to Site. The Sites framework won’t do anything with it, but your project will have full access to it.  
And, if you register SiteExtension in the admin, the “Add” function for SiteExtension will show you the input fields for both models, so it’ll let you create it all at once.

---

<div class="post-metadata">

**Author:** ![anjanesh](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/anjanesh/32/4583_2.png) [@anjanesh](https://forum.djangoproject.com/u/anjanesh)\
**Post date:** [December 11, 2021, 4:17am UTC](https://forum.djangoproject.com/t/sites-framework-or-custom-model-for-multi-sites/10929/5 "2021-12-11T04:17:34Z")

</div>

But when I create a separate class extending Site & registering only Site\_Custom, the dashboard is showing 2 different tables.

models.py :

```auto
class Site_Custom(Site):
    google_analytics_code = models.CharField(max_length=25)
    email = models.EmailField(max_length=100)
    created = models.DateTimeField(auto_now_add=True)
    active = models.BooleanField(default=True)

    def __str__ (self):
        return self.name

```

admin.py :

```auto
from .models import Site_Custom
admin.site.register([Site_Custom])

```

 ![sites](https://us1.discourse-cdn.com/flex026/uploads/djangoproject/original/2X/9/907eaef0ded0ca2c7fd3379c0decd3eb8f683dd6.png)

I want the default Site to be extended and shown as primary.

---

<div class="post-metadata">

**Author:** ![anjanesh](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/anjanesh/32/4583_2.png) [@anjanesh](https://forum.djangoproject.com/u/anjanesh)\
**Post date:** [December 11, 2021, 6:05am UTC](https://forum.djangoproject.com/t/sites-framework-or-custom-model-for-multi-sites/10929/6 "2021-12-11T06:05:28Z")

</div>

I guess the solution is to create a new table with one-to-one link, but I was looking for [single table with additional fields](https://simpleisbetterthancomplex.com/tutorial/2016/07/22/how-to-extend-django-user-model.html#abstractuser).

```auto
from django.contrib.sites.models import Site

class Site_Custom(models.Model):
    site = models.OneToOneField(Site, on_delete=models.CASCADE)
    google_analytics_code = models.CharField(max_length=25)
    email = models.EmailField(max_length=100)
    created = models.DateTimeField(auto_now_add=True)    
    active = models.BooleanField(default=True)

```

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [December 11, 2021, 1:10pm UTC](https://forum.djangoproject.com/t/sites-framework-or-custom-model-for-multi-sites/10929/7 "2021-12-11T13:10:35Z")

</div>

I’m not sure what the link you’re referencing has to do with this topic - it’s a completely different situation and model structure.

But sure, you have a choice. Create your own fork of Django and extend the django.contrib.sites.models package as you see fit. I just never recommend that as an option because long-term, it creates more problems than it solves.
