SlugField in Django
- In General terms A Slug is a short label for something, containing only letters, numbers, underscores or hyphens. They are generally used in URLs.
- A SlugField in Django is like a CharField where you can specify max_length attribute. If max_length is not specified, Django will use a default length of 50.
- Implies setting Field.db_index to True.
- It is often useful to automatically prepopulate a SlugField based on the value of some other value. You can do this automatically in the admin using prepopulated_fields.
- It uses validate_slug or validate_unicode_slug for validation.
Syntax:
field_name = models.SlugField(max_length=100, **options)
Comments
Post a Comment