mirror of
https://github.com/django/django.git
synced 2025-06-04 11:09:13 +00:00
Fixed #25692 -- Added natural keys support to Site model.
This commit is contained in:
parent
81006b9657
commit
0115f9faa5
@ -78,6 +78,9 @@ class SiteManager(models.Manager):
|
|||||||
global SITE_CACHE
|
global SITE_CACHE
|
||||||
SITE_CACHE = {}
|
SITE_CACHE = {}
|
||||||
|
|
||||||
|
def get_by_natural_key(self, domain):
|
||||||
|
return self.get(domain=domain)
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class Site(models.Model):
|
class Site(models.Model):
|
||||||
@ -96,6 +99,9 @@ class Site(models.Model):
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.domain
|
return self.domain
|
||||||
|
|
||||||
|
def natural_key(self):
|
||||||
|
return (self.domain,)
|
||||||
|
|
||||||
|
|
||||||
def clear_site_cache(sender, **kwargs):
|
def clear_site_cache(sender, **kwargs):
|
||||||
"""
|
"""
|
||||||
|
@ -93,7 +93,8 @@ Minor features
|
|||||||
:mod:`django.contrib.sites`
|
:mod:`django.contrib.sites`
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
* ...
|
* The :class:`~django.contrib.sites.models.Site` model now supports
|
||||||
|
:ref:`natural keys <topics-serialization-natural-keys>`.
|
||||||
|
|
||||||
:mod:`django.contrib.staticfiles`
|
:mod:`django.contrib.staticfiles`
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
@ -179,6 +179,10 @@ class SitesFrameworkTests(TestCase):
|
|||||||
with self.assertRaisesMessage(ValidationError, msg):
|
with self.assertRaisesMessage(ValidationError, msg):
|
||||||
site.validate_unique()
|
site.validate_unique()
|
||||||
|
|
||||||
|
def test_site_natural_key(self):
|
||||||
|
self.assertEqual(Site.objects.get_by_natural_key(self.site.domain), self.site)
|
||||||
|
self.assertEqual(self.site.natural_key(), (self.site.domain,))
|
||||||
|
|
||||||
|
|
||||||
class JustOtherRouter(object):
|
class JustOtherRouter(object):
|
||||||
def allow_migrate(self, db, app_label, **hints):
|
def allow_migrate(self, db, app_label, **hints):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user