'AttributeError: 'CharField' object has no attribute 'slugify' when creating slug in django

I'm trying to have my django model automatically create a slug of the model name, but I get this error:

AttributeError: 'CharField' object has no attribute 'slugify'

This is my code:

from django.db import models
from django.utils.text import slugify

class school (models.Model):
    name = models.CharField(max_length=50)
    description = models.CharField(max_length=750)
    location = models.CharField(max_length=19, choices=location_choices)
    picture = models.URLField(max_length=200, default="https://i.ibb.co/0MZ5mFt/download.jpg")
    slug = models.SlugField(unique=True, default=name.slugify(), editable=False)


Solution 1:[1]

Simple fix - I had to change name.slugify() to slugify(name).

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Kovy Jacob