Hey guys-
I'm following the tutorial and on step 4 I'm trying to post a snippet with a username/password like this example:
But I get this error:
"owner": [
"This field is required."
]
I'm able to login through the browsable API and post snippets for each user there. But it's not working from the command line.
I also noticed that my owner values saved in the database are numeric id's (e.g. 1, 2) instead of my usernames like the tutorial shows.
The tutorial shows this response:
{
"id": 5,
"owner": "tom",
"title": "foo",
"code": "print 789",
"linenos": false,
"language": "python",
"style": "friendly"
}
But my snippets look like this, note the numeric "owner" value even though I'm logged in as user "joe":
{
"id": 1,
"owner": 2,
"title": "Test",
"code": "Code for Test",
"linenos": true,
"language": "abap",
"style": "algol",
}
I'm new to python and django. So I'm probably overlooking the obvious. I haven't done any extra steps besides what the tutorial told me to do. I tried finding an answer to this and found a post that suggested adding the following code:
def pre_save(self, obj):
obj.owner = self.request.user
But that didn't make a difference.
Any thoughts on what step I might have messed up in the tutorial?
Thanks!