validate redirecting slugs properly
import json
import operator
import os
-from django.core.validators import validate_slug
from functools import reduce
from itertools import chain
@@ -177,7 +176,6 @@ class EditorFormBase(I18nModelFormMixin, ModelForm):
self.add_redirect_slugs = None
self.remove_redirect_slugs = None
if 'slug' in self.fields:
- self.fields['slug'].validators.append(validate_slug)
self.redirect_slugs = sorted(self.instance.redirects.values_list('slug', flat=True))
self.fields['redirect_slugs'] = CharField(label=_('Redirecting Slugs (comma seperated)'), required=False,
initial=','.join(self.redirect_slugs))
@@ -208,8 +206,10 @@ class EditorFormBase(I18nModelFormMixin, ModelForm):
self.add_redirect_slugs = new_redirect_slugs - old_redirect_slugs
self.remove_redirect_slugs = old_redirect_slugs - new_redirect_slugs
+ model_slug_field = self._meta.model._meta.get_field('slug')
for slug in self.add_redirect_slugs:
self.fields['slug'].run_validators(slug)
+ model_slug_field.run_validators(slug)
LocationSlug = self.request.changeset.wrap_model('LocationSlug')
qs = LocationSlug.objects.filter(slug__in=self.add_redirect_slugs)
