Fixed #23945 -- Made default site use the configured SITE_ID.

This commit is contained in:
wrwrwr 2014-11-30 18:03:40 +01:00 committed by Tim Graham
parent 1739ae9edc
commit bfc75996f9
3 changed files with 14 additions and 1 deletions

View File

@ -3,6 +3,7 @@ Creates the default Site object.
""" """
from django.apps import apps from django.apps import apps
from django.conf import settings
from django.core.management.color import no_style from django.core.management.color import no_style
from django.db import DEFAULT_DB_ALIAS, connections, router 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. # can also crop up outside of tests - see #15346.
if verbosity >= 2: if verbosity >= 2:
print("Creating example.com Site object") 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, # We set an explicit pk instead of relying on auto-incrementation,
# so we need to reset the database sequence. See #17415. # so we need to reset the database sequence. See #17415.

View File

@ -176,6 +176,14 @@ class CreateDefaultSiteTests(TestCase):
post_migrate.send(sender=self.app_config, app_config=self.app_config, verbosity=0) post_migrate.send(sender=self.app_config, app_config=self.app_config, verbosity=0)
self.assertTrue(Site.objects.exists()) 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): class MiddlewareTest(TestCase):

View File

@ -168,6 +168,10 @@ Minor features
<django.http.HttpRequest.get_host>` if the :setting:`SITE_ID` setting is not <django.http.HttpRequest.get_host>` if the :setting:`SITE_ID` setting is not
defined. 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` :mod:`django.contrib.staticfiles`
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^