diff --git a/CHANGELOG.rst b/CHANGELOG.rst index ee21e72fc186033ee3e0fcb67c7ac14e0aa0a0c2..999c1e93963046c17c0b0339baef24ae41fd6d33 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -12,7 +12,7 @@ and this project adheres to `Semantic Versioning`_. Changed ~~~~~~~~ -* Ensure uniqueness per site of FAQ sections and categories. +* Ensure uniqueness per site of FAQ sections and categories with parents. `2.0b0`_ - 2021-05-21 diff --git a/aleksis/apps/hjelp/migrations/0004_unique_constraints.py b/aleksis/apps/hjelp/migrations/0004_unique_constraints.py index 7c281c744b6407096c7bc1a6310bb9f3020d530f..9d57f65f5941f8fa3222c61c3bf8297729b5f0b9 100644 --- a/aleksis/apps/hjelp/migrations/0004_unique_constraints.py +++ b/aleksis/apps/hjelp/migrations/0004_unique_constraints.py @@ -44,6 +44,10 @@ class Migration(migrations.Migration): ), migrations.AddConstraint( model_name='issuecategory', - constraint=models.UniqueConstraint(fields=('site_id', 'name'), name='unique_category_name_per_site'), + constraint=models.UniqueConstraint(fields=('site_id', 'name'), condition=models.Q(parent='null'), name='unique_category_name_per_site_without_parent'), + ), + migrations.AddConstraint( + model_name='issuecategory', + constraint=models.UniqueConstraint(fields=('site_id', 'name', 'parent'), name='unique_category_name_per_site_with_parent'), ), ] diff --git a/aleksis/apps/hjelp/models.py b/aleksis/apps/hjelp/models.py index 0610c91d6e23eaccfe2ea6b840daee9fd73872e2..c7c3f778cb5de433ca4c895b457bd2ef19cdef78 100644 --- a/aleksis/apps/hjelp/models.py +++ b/aleksis/apps/hjelp/models.py @@ -102,6 +102,12 @@ class IssueCategory(ExtensibleModel): constraints = [ models.UniqueConstraint( - fields=["site_id", "name"], name="unique_category_name_per_site" - ) + fields=["site_id", "name"], + condition=models.Q(parent="null"), + name="unique_category_name_per_site_without_parent", + ), + models.UniqueConstraint( + fields=["site_id", "name", "parent"], + name="unique_category_name_per_site_with_parent", + ), ]