unique page slug
This commit is contained in:
parent
0e48b9844c
commit
87df063bb4
|
@ -98,9 +98,11 @@ class Page(models.Model):
|
||||||
return '{}'.format(self.title or self.pk)
|
return '{}'.format(self.title or self.pk)
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
# TODO: ensure unique slug
|
|
||||||
if not self.slug:
|
if not self.slug:
|
||||||
self.slug = slugify(self.title)
|
self.slug = slugify(self.title)
|
||||||
|
count = Page.objects.all(slug__startswith=self.slug).count()
|
||||||
|
if count:
|
||||||
|
self.slug += '-' + count
|
||||||
if self.is_published and self.pub_date is None:
|
if self.is_published and self.pub_date is None:
|
||||||
self.pub_date = tz.datetime.now()
|
self.pub_date = tz.datetime.now()
|
||||||
elif not self.is_published:
|
elif not self.is_published:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user