1# shell/bash
2pip install python-slugify
3# or
4pip3 install python-slugify
5
6# python
7from slugify import slugify
1from django.template.defaultfilters import slugify
2
3# in the view maybe while saving the form...
4def savedata()
5 form = someform(request.POST or None)
6 if form.is_valid():
7 new_post = form.save(commit=False) #for holding it before actually saving
8 # slugify returns elephant-is-big if passed slugify("elephant is big")
9 # and therefore a hyphened slug
10 new_post.slug = slugify(form.title)
11 new_post.save()
12
13# model may look like this
14class SomeModel(models.Model):
15 title = models.Charfield()
16 slug = models.SlugField(unique=True)
17 ## other fields