django autoslug

django-autoslug library

The AutoSlugField is not a built-in field provided by Django itself. It appears to be from a third-party library called django-autoslug. This library provides a field for Django models that automatically generates a unique slug for each instance of the model.

To use AutoSlugField, you need to install the django-autoslug library via pip. You can do this by running:

Bash
pip install django-autoslug

Once installed, you can import AutoSlugField in your Django model file and use it like any other field. Here's a basic example of how you might use it:

Python
  from django.db import models
  from autoslug import AutoSlugField

  class YourModel(models.Model):
  title = models.CharField(max_length=100)
  slug = AutoSlugField(populate_from='title', unique=True)

In this example, the slug field will automatically generate a slug based on the title field whenever a new instance of YourModel is created. The unique=True parameter ensures that each generated slug is unique within the database.