django - Why doesn't my save method work in the admin? -
in model overwrite save-method blog model auto-populate slug field using slugify method.
class blogpost(models.model): title = models.charfield(max_length=100,unique=true) slug = models.slugfield(max_length=100,unique=true) date = models.datetimefield(auto_now_add=true) author = models.foreignkey(author) body = models.textfield() category = models.foreignkey(blogcategory) def save(self, *args, **kwargs): if not self.id: # newly created object, set slug self.slug = slugify(self.title) super(blogpost, self).save(*args, **kwargs) but creating new object in admin interface doesn't work without either setting slug field manually or doing like
class blogpostadmin(admin.modeladmin): prepopulated_fields = {"slug": ("title",)} basically have same functionality defined twice. ideas on how avoid this? and: why doesn't work own save method in admin?
you should put blank=true in definition of slug field.
Comments
Post a Comment