Skip to content

Commit

Permalink
Added an optional setting to allow the slug to be changed
Browse files Browse the repository at this point in the history
  • Loading branch information
Corey Oordt committed Oct 22, 2009
1 parent e1da454 commit 58a2280
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 3 additions & 1 deletion categories/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
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."""
Expand All @@ -30,7 +31,8 @@ class Meta:
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):
Expand Down
3 changes: 3 additions & 0 deletions categories/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.conf import settings

ALLOW_SLUG_CHANGE = getattr(settings, 'CATEGORIES_ALLOW_SLUG_CHANGE', False)

0 comments on commit 58a2280

Please sign in to comment.