summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwrwrwr <git@wr.waw.pl>2014-11-30 18:03:40 +0100
committerTim Graham <timograham@gmail.com>2014-12-01 19:36:50 -0500
commitbfc75996f9b7486929f0c4340bca54a8afa7ecfb (patch)
treee121a5ec81e9a03acf625ae4cf57d9219c584958
parent1739ae9edc6e6c07ca20cad36dd15316f18f3f8e (diff)
Fixed #23945 -- Made default site use the configured SITE_ID.
-rw-r--r--django/contrib/sites/management.py3
-rw-r--r--django/contrib/sites/tests.py8
-rw-r--r--docs/releases/1.8.txt4
3 files changed, 14 insertions, 1 deletions
diff --git a/django/contrib/sites/management.py b/django/contrib/sites/management.py
index 975bafe1ff..a9daf1cc75 100644
--- a/django/contrib/sites/management.py
+++ b/django/contrib/sites/management.py
@@ -3,6 +3,7 @@ Creates the default Site object.
"""
from django.apps import apps
+from django.conf import settings
from django.core.management.color import no_style
from django.db import DEFAULT_DB_ALIAS, connections, router
@@ -24,7 +25,7 @@ def create_default_site(app_config, verbosity=2, interactive=True, db=DEFAULT_DB
# can also crop up outside of tests - see #15346.
if verbosity >= 2:
print("Creating example.com Site object")
- Site(pk=1, domain="example.com", name="example.com").save(using=db)
+ Site(pk=settings.SITE_ID, domain="example.com", name="example.com").save(using=db)
# We set an explicit pk instead of relying on auto-incrementation,
# so we need to reset the database sequence. See #17415.
diff --git a/django/contrib/sites/tests.py b/django/contrib/sites/tests.py
index 5b6b1fc4a8..72c7a9f8c7 100644
--- a/django/contrib/sites/tests.py
+++ b/django/contrib/sites/tests.py
@@ -176,6 +176,14 @@ class CreateDefaultSiteTests(TestCase):
post_migrate.send(sender=self.app_config, app_config=self.app_config, verbosity=0)
self.assertTrue(Site.objects.exists())
+ @override_settings(SITE_ID=35696)
+ def test_custom_site_id(self):
+ """
+ #23945 - The configured ``SITE_ID`` should be respected.
+ """
+ create_default_site(self.app_config, verbosity=0)
+ self.assertEqual(Site.objects.get().pk, 35696)
+
class MiddlewareTest(TestCase):
diff --git a/docs/releases/1.8.txt b/docs/releases/1.8.txt
index f96067fa81..4afa02dd18 100644
--- a/docs/releases/1.8.txt
+++ b/docs/releases/1.8.txt
@@ -168,6 +168,10 @@ Minor features
<django.http.HttpRequest.get_host>` if the :setting:`SITE_ID` setting is not
defined.
+* The default :class:`~django.contrib.sites.models.Site` created when running
+ ``migrate`` now respects the :setting:`SITE_ID` setting (instead of always
+ using ``pk=1``).
+
:mod:`django.contrib.staticfiles`
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^