Permalink
Browse files

Merge pull request #1 from sdornan/patch-1

Fix updating models with slugs that end with a number
  • Loading branch information...
2 parents 8eea4da + 3e0a018 commit 0dbe659d293d152a49e4cd996a985dcb6684b563 @sdornan committed Feb 24, 2012
Showing with 10 additions and 15 deletions.
  1. +10 −15 django_extensions/db/fields/__init__.py
@@ -76,21 +76,16 @@ def create_slug(self, model_instance, add):
self._populate_from = (self._populate_from, )
slug_field = model_instance._meta.get_field(self.attname)
- if add or self.overwrite:
- # slugify the original field content and set next step to 2
- slug_for_field = lambda field: self.slugify_func(getattr(model_instance, field))
- slug = self.separator.join(map(slug_for_field, self._populate_from))
- next = 2
- else:
- # get slug from the current model instance and calculate next
- # step from its number, clean-up
+ if not add and not self.overwrite:
+ # no point in recalculating a slug if we already have a
+ # perfectly good one stored on the instance
slug = self._slug_strip(getattr(model_instance, self.attname))
- next = slug.split(self.separator)[-1]
- if next.isdigit() and not self.allow_duplicates:
- slug = self.separator.join(slug.split(self.separator)[:-1])
- next = int(next)
- else:
- next = 2
+ return slug
+
+ # slugify the original field content and set next step to 2
+ slug_for_field = lambda field: self.slugify_func(getattr(model_instance, field))
+ slug = self.separator.join(map(slug_for_field, self._populate_from))
+ next = 2
# strip slug depending on max_length attribute of the slug field
# and clean-up
@@ -109,7 +104,7 @@ def create_slug(self, model_instance, add):
if model_instance.pk:
queryset = queryset.exclude(pk=model_instance.pk)
- # form a kwarg dict used to impliment any unique_together contraints
+ # form a kwarg dict used to implement any unique_together contraints
kwargs = {}
for params in model_instance._meta.unique_together:
if self.attname in params:

0 comments on commit 0dbe659

Please sign in to comment.