From 0eeeeee36e1f327f57bf815254923b494054af76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Dlouh=C3=BD?= Date: Fri, 5 Oct 2018 15:59:21 +0200 Subject: [PATCH] make Category.slug unique --- README.rst | 6 ++++++ categories/base.py | 2 +- .../migrations/0003_auto_20181005_1559.py | 18 ++++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 categories/migrations/0003_auto_20181005_1559.py diff --git a/README.rst b/README.rst index a1e7dc18..be1d20b4 100644 --- a/README.rst +++ b/README.rst @@ -13,6 +13,12 @@ Django Categories grew out of our need to provide a basic hierarchical taxonomy As a news site, our stories, photos, and other content get divided into "sections" and we wanted all the apps to use the same set of sections. As our needs grew, the Django Categories grew in the functionality it gave to category handling within web pages. +======= +New in 2.0 +========== + +* Category.slug becomes unique. You must remove all duplicates in category slugs before running migrations. + New in 1.4 ========== diff --git a/categories/base.py b/categories/base.py index eb1ccd34..0d0e048b 100644 --- a/categories/base.py +++ b/categories/base.py @@ -44,7 +44,7 @@ class CategoryBase(MPTTModel): verbose_name=_('parent'), ) name = models.CharField(max_length=100, verbose_name=_('name')) - slug = models.SlugField(verbose_name=_('slug')) + slug = models.SlugField(verbose_name=_('slug'), unique=True) active = models.BooleanField(default=True, verbose_name=_('active')) objects = CategoryManager() diff --git a/categories/migrations/0003_auto_20181005_1559.py b/categories/migrations/0003_auto_20181005_1559.py new file mode 100644 index 00000000..326a4408 --- /dev/null +++ b/categories/migrations/0003_auto_20181005_1559.py @@ -0,0 +1,18 @@ +# Generated by Django 2.0.9 on 2018-10-05 13:59 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('categories', '0002_auto_20170217_1111'), + ] + + operations = [ + migrations.AlterField( + model_name='category', + name='slug', + field=models.SlugField(unique=True, verbose_name='slug'), + ), + ]