Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force model fields to be full in the url #389

Open
miki725 opened this issue Feb 27, 2012 · 4 comments
Open

Force model fields to be full in the url #389

miki725 opened this issue Feb 27, 2012 · 4 comments

Comments

@miki725
Copy link

miki725 commented Feb 27, 2012

Is there any way to overwrite if the field in the modelresource should be full in the resource's url?

Basically if the resourcemodel is:

class FooResource(ModelResource):
    foo = fields.ForeignKey(FooFooResource, 'foo', full=True)

then to overwrite it in the url by doing

example.com/api/foo/?foo__full=false

or

example.com/api/foo/?foo__full=true
@toastdriven
Copy link
Contributor

There isn't a built-in way to do this right now. It's possible to do in dehydrate, checking if bundle.request.GET.get('foo__full', True) == False then just swapping out the data in bundle.data. Takes a little bit of code though.

@santiagobasulto
Copy link

I created a quick fix for this issue: https://gist.github.com/2897326

I think it should be really easy to integrate it into the core.

@toastdriven Do you want me to give it a try?

@toastdriven
Copy link
Contributor

@santiagobasulto Unfortunately, that's modifying the field on the instance, likely causing subsequent requests to have behavior "leaked" from previous requests. -0 on that implementation.

@paulcollinsiii
Copy link

So @toastdriven I've got another way of doing this in the dehydrate_related function
https://gist.github.com/3846876

This is just kinda a dump of how I'm using it now. I'd like to add permissions checking via the Meta class filtering section, but wanted to get a quick "Yay this idea looks good" or "Boo, this causes other problems"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants