mirror of
https://github.com/jazzband/django-categories.git
synced 2026-03-16 22:30:24 +00:00
Added an optional setting to allow the slug to be changed
This commit is contained in:
parent
e1da454bee
commit
58a2280c2b
2 changed files with 6 additions and 1 deletions
|
|
@ -4,6 +4,7 @@ from django import forms
|
|||
from django.template.defaultfilters import slugify
|
||||
from mptt.forms import TreeNodeChoiceField
|
||||
from editor.tree_editor import TreeEditor
|
||||
from settings import ALLOW_SLUG_CHANGE
|
||||
|
||||
class NullTreeNodeChoiceField(forms.ModelChoiceField):
|
||||
"""A ModelChoiceField for tree nodes."""
|
||||
|
|
@ -30,7 +31,8 @@ class CategoryAdminForm(forms.ModelForm):
|
|||
model = Category
|
||||
|
||||
def clean_slug(self):
|
||||
self.cleaned_data['slug'] = slugify(self.cleaned_data['name'])
|
||||
if self.instance is None or ALLOW_SLUG_CHANGE:
|
||||
self.cleaned_data['slug'] = slugify(self.cleaned_data['name'])
|
||||
return self.cleaned_data['slug']
|
||||
|
||||
def clean(self):
|
||||
|
|
|
|||
3
categories/settings.py
Normal file
3
categories/settings.py
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
from django.conf import settings
|
||||
|
||||
ALLOW_SLUG_CHANGE = getattr(settings, 'CATEGORIES_ALLOW_SLUG_CHANGE', False)
|
||||
Loading…
Reference in a new issue