我试图为模型生成自动slug,只要它是空的,来自另一个字段。这是代码:
class Position(RichText):
name = models.CharField(max_length=200)
slug = models.SlugField(null=True)
def position_description(self):
return self.content
def __unicode__(self):
return self.name
def save(self, *args, **kwargs):
if not self.slug:
self.slug = slugify(self.name)
super(Position, self).save(*args, **kwargs)
当我使用loaddata加载初始灯具时,似乎永远不会触发save()
方法。这是正常的行为吗?我怎么能抓住灯具?