diff options
| author | Piotr Jakimiak <pj306228@students.mimuw.edu.pl> | 2015-05-14 19:59:36 +0200 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2015-05-16 08:43:42 -0400 |
| commit | 70e3e2e08ee1d07343d48b1db9df838db3efb0e2 (patch) | |
| tree | 2fe2e8536a198d666dcb4ef582f77d78d1d2c74b | |
| parent | 4c2197db32deaea2f0c3d04c2c36bb7df6a2e06c (diff) | |
Fixed #24774 -- Made contrib.site's Site.domain field unique
| -rw-r--r-- | AUTHORS | 1 | ||||
| -rw-r--r-- | django/contrib/sites/migrations/0002_alter_domain_unique.py | 20 | ||||
| -rw-r--r-- | django/contrib/sites/models.py | 2 | ||||
| -rw-r--r-- | docs/ref/contrib/sites.txt | 5 | ||||
| -rw-r--r-- | docs/releases/1.9.txt | 3 | ||||
| -rw-r--r-- | tests/sites_tests/tests.py | 6 |
6 files changed, 36 insertions, 1 deletions
@@ -565,6 +565,7 @@ answer newbie questions, and generally made Django that much better: Philip Lindborg <philip.lindborg@gmail.com> Philippe Raoult <philippe.raoult@n2nsoft.com> phil@produxion.net + Piotr Jakimiak <piotr.jakimiak@gmail.com> Piotr Lewandowski <piotr.lewandowski@gmail.com> plisk polpak@yahoo.com diff --git a/django/contrib/sites/migrations/0002_alter_domain_unique.py b/django/contrib/sites/migrations/0002_alter_domain_unique.py new file mode 100644 index 0000000000..e7f414fb5c --- /dev/null +++ b/django/contrib/sites/migrations/0002_alter_domain_unique.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +import django.contrib.sites.models +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('sites', '0001_initial'), + ] + + operations = [ + migrations.AlterField( + model_name='site', + name='domain', + field=models.CharField(max_length=100, unique=True, validators=[django.contrib.sites.models._simple_domain_name_validator], verbose_name='domain name'), + ), + ] diff --git a/django/contrib/sites/models.py b/django/contrib/sites/models.py index d7026d0355..6471dca136 100644 --- a/django/contrib/sites/models.py +++ b/django/contrib/sites/models.py @@ -73,7 +73,7 @@ class SiteManager(models.Manager): class Site(models.Model): domain = models.CharField(_('domain name'), max_length=100, - validators=[_simple_domain_name_validator]) + validators=[_simple_domain_name_validator], unique=True) name = models.CharField(_('display name'), max_length=50) objects = SiteManager() diff --git a/docs/ref/contrib/sites.txt b/docs/ref/contrib/sites.txt index 8c71ca0572..4928c92119 100644 --- a/docs/ref/contrib/sites.txt +++ b/docs/ref/contrib/sites.txt @@ -23,6 +23,11 @@ The sites framework is mainly based on a simple model: The domain name associated with the Web site. + .. versionchanged:: 1.9 + + The ``domain`` field was set to be + :attr:`~django.db.models.Field.unique`. + .. attribute:: name A human-readable "verbose" name for the Web site. diff --git a/docs/releases/1.9.txt b/docs/releases/1.9.txt index 473e64f95d..c2ceb5f5db 100644 --- a/docs/releases/1.9.txt +++ b/docs/releases/1.9.txt @@ -447,6 +447,9 @@ Miscellaneous * Support for PostGIS 1.5 has been dropped. +* The ``django.contrib.sites.models.Site.domain`` field was changed to be + :attr:`~django.db.models.Field.unique`. + .. _deprecated-features-1.9: Features deprecated in 1.9 diff --git a/tests/sites_tests/tests.py b/tests/sites_tests/tests.py index 128420a17b..563ee6a681 100644 --- a/tests/sites_tests/tests.py +++ b/tests/sites_tests/tests.py @@ -135,6 +135,12 @@ class SitesFrameworkTests(TestCase): clear_site_cache(Site, instance=site, using='default') self.assertEqual(models.SITE_CACHE, {}) + def test_unique_domain(self): + site = Site(domain=self.site.domain) + msg = 'Site with this Domain name already exists.' + with self.assertRaisesMessage(ValidationError, msg): + site.validate_unique() + class JustOtherRouter(object): def allow_migrate(self, db, app_label, **hints): |
