1
0
mirror of https://github.com/django/django.git synced 2024-12-22 17:16:24 +00:00

Fixed #25692 -- Added natural keys support to Site model.

This commit is contained in:
j0hnsmith 2015-11-06 22:55:44 +00:00 committed by Tim Graham
parent 81006b9657
commit 0115f9faa5
3 changed files with 12 additions and 1 deletions

View File

@ -78,6 +78,9 @@ class SiteManager(models.Manager):
global SITE_CACHE
SITE_CACHE = {}
def get_by_natural_key(self, domain):
return self.get(domain=domain)
@python_2_unicode_compatible
class Site(models.Model):
@ -96,6 +99,9 @@ class Site(models.Model):
def __str__(self):
return self.domain
def natural_key(self):
return (self.domain,)
def clear_site_cache(sender, **kwargs):
"""

View File

@ -93,7 +93,8 @@ Minor features
: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`
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -179,6 +179,10 @@ class SitesFrameworkTests(TestCase):
with self.assertRaisesMessage(ValidationError, msg):
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):
def allow_migrate(self, db, app_label, **hints):