如果有人好奇,解决方案是重写restore_object方法,并在实例化后将额外的实例变量添加到注释对象:
def restore_object(self, attrs, instance=None): if instance is not None: instance.email = attrs.get('email', instance.email) instance.author = attrs.get('author', instance.author) instance.url = attrs.get('url', instance.url) instance.content = attrs.get('content', instance.content) instance.ip = attrs.get('ip', instance.ip) instance.post_title = attrs.get('post_title', instance.post_title) instance.post_url = attrs.get('post_url', instance.post_url) return instance commenter_pw = attrs.get('commenter_pw') del attrs['commenter_pw'] comment = Comment(**attrs) comment.commenter_password = commenter_pw return comment


