0👍
try:
def create_detail(self, object_list, bundle):
return bundle.obj == bundle.request.user
0👍
It looks like bundle.obj isn’t populated during the create_detail authorization.
Also, create_detail for a user really doesn’t make much sense, because there’s no object for the user to own until its created anyways. You could just check if bundle.request.user is a valid user with permissions on the model.
In my case, I needed to check if the created object referenced an object owned by the user, so here’s what I came up with:
def create_detail(self, object_list, bundle):
resource=BookResource()
book=resource.get_via_uri(bundle.data["book"], bundle.request)
return book.user == bundle.request.user
Anyways, bottom line: tastypie’s docs are a little off.
And, I hope this helps.
- [Django]-Dynamic SEO-friendly URLs
- [Django]-How to use SearchHeadline with SearchVector on multiple fields
- [Django]-Django collectstatic on S3 uploads unchanged files everytime on Heroku
- [Django]-I have multiple django tables and want to query the tables in parallel
Source:stackexchange.com