Skip to content

Commit

Permalink
make Category.slug unique
Browse files Browse the repository at this point in the history
  • Loading branch information
PetrDlouhy committed Mar 13, 2020
1 parent a3a3f81 commit 0484bc9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
5 changes: 5 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ 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 1.8
==========

* Category.slug becomes unique. If there are any duplicates in category slugs, the migration will add sequence number to them.

New in 1.7
==========

Expand Down
2 changes: 1 addition & 1 deletion categories/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,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()
Expand Down
18 changes: 18 additions & 0 deletions categories/migrations/0004_unique_category_slug.py
Original file line number Diff line number Diff line change
@@ -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', '0003_auto_20200306_1050'),
]

operations = [
migrations.AlterField(
model_name='category',
name='slug',
field=models.SlugField(unique=True, verbose_name='slug'),
),
]

0 comments on commit 0484bc9

Please sign in to comment.