覆盖save方法的用途是每次保存模型实例时执行一些操作。
在您的示例中,每次保存模型实例时,该
save方法都会使用函数将名称值转换为从属值,
slugify()并将其保存到从属字段中。
这是一种将名称值自动转换为段值,然后将其保存在段值字段中的方法。
def save(self, *args, **kwargs): #this line below give to the instance slug field a slug name self.slug = slugify(self.name) #this line below save every fields of the model instance super(Category, self).save(*args, **kwargs)
例如,在此模型的表单中,您将不必包括slug字段的输入,save方法将根据名称输入的值填充该字段。



