def save(self, *args, **kwargs):
if self.parent and self.share_of:
raise ValueError("Can't be both a reply and a share!")
self.cache_data()
if self.parent:
self.content_type = ContentType.REPLY
# Ensure replies have sane values
self.visibility = self.parent.visibility
self.pinned = False
elif self.share_of:
self.content_type = ContentType.SHARE
if not self.pk:
if not self.guid:
self.guid = uuid4()
if self.pinned:
max_order = Content.objects.top_level().filter(author=self.author).aggregate(Max("order"))["order__max"]
if max_order is not None: # If max_order is None, there is likely to be no content yet
self.order = max_order + 1
self.fix_local_uploads()
super().save(*args, **kwargs)
self.cache_related_object_data()
评论列表
文章目录