Repository: kartoza/prj.app

Issue:
Validation incorrect on version admin form for slug
A slug that is accepted in the frontend is refused in the backend. This means you cannot edit existing Versions in admin

<img width="994" alt="image" src="https://user-images.githubusercontent.com/178003/76130875-3bf0e480-6004-11ea-8348-e4dd4eebb5a4.png">



Discussion:

Resolving patch:
diff --git a/django_project/changes/migrations/0009_auto_20200311_1321.py b/django_project/changes/migrations/0009_auto_20200311_1321.py
new file mode 100644
--- /dev/null
+++ b/django_project/changes/migrations/0009_auto_20200311_1321.py
@@ -0,0 +1,19 @@
+# Generated by Django 2.2 on 2020-03-11 11:21
+
+import changes.utils.custom_slugfield
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('changes', '0008_auto_20200129_1151'),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name='version',
+            name='slug',
+            field=changes.utils.custom_slugfield.CustomSlugField(),
+        ),
+    ]
diff --git a/django_project/changes/models/version.py b/django_project/changes/models/version.py
--- a/django_project/changes/models/version.py
+++ b/django_project/changes/models/version.py
@@ -1,7 +1,6 @@
 # coding=utf-8
 import re
 from django.urls import reverse
-# from django.utils.text import slugify
 from common.utilities import version_slugify
 import os
 import logging
@@ -12,6 +11,7 @@
 from django.contrib.auth.models import User
 from django.utils.translation import ugettext_lazy as _
 from django.db import models
+from ..utils.custom_slugfield import CustomSlugField
 
 logger = logging.getLogger(__name__)
 
@@ -57,7 +57,7 @@ class Version(models.Model):
         blank=True)
 
     author = models.ForeignKey(User, on_delete=models.CASCADE)
-    slug = models.SlugField()
+    slug = CustomSlugField()
     project = models.ForeignKey('base.Project', on_delete=models.CASCADE)
     objects = models.Manager()
 
diff --git a/django_project/changes/utils/custom_slugfield.py b/django_project/changes/utils/custom_slugfield.py
new file mode 100644
--- /dev/null
+++ b/django_project/changes/utils/custom_slugfield.py
@@ -0,0 +1,38 @@
+# coding=utf-8
+import re
+from django.core.validators import RegexValidator
+from django.db.models.fields import SlugField
+from django.forms.fields import SlugField as SlugFieldForm
+
+
+slug_re = re.compile(r'^[-a-zA-Z0-9_.]+\Z')
+custom_validate_slug = RegexValidator(
+        slug_re,
+        u"Enter a valid 'slug' consisting of letters, numbers, underscores, "
+        u"dots or hyphens.",
+        'invalid')
+
+
+class CustomFormSlugField(SlugFieldForm):
+    """A custom slugfield form where dots are allowed in the slug."""
+
+    default_validators = [custom_validate_slug]
+    default_error_messages = {
+        'invalid': u"Enter a valid 'slug' consisting of letters, numbers, "
+                   u"underscores, dots or hyphens.",
+    }
+
+
+class CustomSlugField(SlugField):
+    """A custom slugfield where dots are allowed in the slug."""
+
+    default_validators = [custom_validate_slug]
+    default_error_messages = {
+        'invalid': u"Enter a valid 'slug' consisting of letters, numbers, "
+                   u"underscores, dots or hyphens.",
+    }
+
+    def formfield(self, **kwargs):
+        defaults = {'form_class': CustomFormSlugField}
+        defaults.update(kwargs)
+        return super(SlugField, self).formfield(**defaults)


Test patch: