Auto Slug field in Django

While designing database, many times we need slug field which we populate from some other field of the same model.

We can set auto slug field so that we don’t need to code in order to populate slug field while insert or update.

You can use the field AutoSlugField from module django-autoslug.

1. Install module django-autoslug.
pip install django-autoslug

2. Import in models file where your model exists.
from autoslug import AutoSlugField

3. Set field in model
E.g.
title = models.CharField(max_length=100)
slug = AutoSlugField(populate_from=’title’,default=None)