I have a model Comment that when created may or may not create a new user. For this reason, my API requires a password field when creating a new comment. Here is my Comment
If anyone is curious, the solution is to override the restore_object method and add the extra instance variable to the comment object after it has been instantiated:
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