def save(self, *args, **kwargs):
self.full_clean()
update_descendant_url_paths = False
is_new = self.id is None
if is_new:
self.set_url_path(self.get_parent())
else:
# update url paths if:
# a) update_fields is specified and it includes any slug field
# or
# b) update_fields is not specified (check all slug fields in that case)
slug_fields = get_translation_fields('slug')
update_fields = kwargs.get('update_fields', slug_fields)
updated_slug_fields = [f for f in slug_fields if f in update_fields]
if updated_slug_fields:
old_record = Page.objects.get(id=self.id)
if any(getattr(old_record, f) != getattr(self, f) for f in updated_slug_fields):
self.set_url_path(self.get_parent())
update_descendant_url_paths = True
result = super(Page, self).save(*args, **kwargs)
if update_descendant_url_paths:
self._update_descendant_lang_url_paths(old_record)
if Site.objects.filter(root_page=self).exists():
delete_root_path_cache()
if is_new:
cls = type(self)
logger.info(
"Page created: \"%s\" id=%d content_type=%s.%s path=%s",
self.title,
self.id,
cls._meta.app_label,
cls.__name__,
self.url_path
)
return result
评论列表
文章目录