summaryrefslogtreecommitdiffstats
path: root/combo/data/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'combo/data/models.py')
-rw-r--r--combo/data/models.py10
1 files changed, 4 insertions, 6 deletions
diff --git a/combo/data/models.py b/combo/data/models.py
index da81df4..8a2ad5a 100644
--- a/combo/data/models.py
+++ b/combo/data/models.py
@@ -174,17 +174,13 @@ class Page(models.Model):
max_order = Page.objects.all().aggregate(Max('order')).get('order__max') or 0
self.order = max_order + 1
if not self.slug:
- if Page.objects.count() == 0:
+ if not Page.objects.exists():
slug = 'index'
else:
base_slug = slugify(self.title)[:40]
slug = base_slug.strip('-')
i = 1
- while True:
- try:
- Page.objects.get(slug=slug, parent_id=self.parent_id)
- except ObjectDoesNotExist:
- break
+ while Page.objects.filter(slug=slug, parent_id=self.parent_id).exists():
i += 1
slug = '%s-%s' % (base_slug, i)
self.slug = slug
@@ -442,6 +438,8 @@ class Page(models.Model):
new_page.pk = None
# set title
new_page.title = _('Copy of %s') % self.title
+ # reset slug
+ new_page.slug = None
# reset snapshot
new_page.snapshot = None
# set order