Open sunjoomoon opened 10 years ago
A very simple example:
>>> import slugify
>>> slugify.slugify('hello there')
u'hello-there'
@sunjoomoon, to use with django you need django-autoslug then...
#models.py
from django.db import models
from autoslug import AutoSlugField
class Article(models.Model):
'''An article with title, date and slug. The slug is not totally
unique but there will be no two articles with the same slug within
any month.
'''
title = models.CharField(max_length=200)
pub_date = models.DateField(auto_now_add=True)
slug = AutoSlugField(populate_from='title', unique_with='pub_date__month')
#settings.py
AUTOSLUG_SLUGIFY_FUNCTION = 'slugify.slugify'
or
#models.py
from django.db import models
from autoslug import AutoSlugField
from slugify import slugify
class Article(models.Model):
'''An article with title, date and slug. The slug is not totally
unique but there will be no two articles with the same slug within
any month.
'''
title = models.CharField(max_length=200)
pub_date = models.DateField(auto_now_add=True)
slug = AutoSlugField(populate_from='title', unique_with='pub_date__month', slugify=slugify)
No settings.py changes.
As a newbie, having tried many but without success, any working example ?