def validate_parent(self, value):
# Validate parent cannot be changed
if self.instance and value != self.instance.parent:
raise serializers.ValidationError("Parent cannot be changed for an existing Content instance.")
# Validate user can see parent
if not self.instance and value:
request = self.context.get("request")
if not value.visible_for_user(request.user):
raise serializers.ValidationError("Parent not found")
return value
评论列表
文章目录