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

Filter by list of ids of a FK #18

Closed
catalanojuan opened this issue Feb 23, 2016 · 6 comments
Closed

Filter by list of ids of a FK #18

catalanojuan opened this issue Feb 23, 2016 · 6 comments
Labels

Comments

@catalanojuan
Copy link

Hi there,

First of all many thanks for sharing this with the world. It might have saved me a lot of time :)

I'm using django-url-filter 0.2.0 DRF integration with DRF 3.3.2 and Django 1.9.2.

One of the 2 uses I'd like to give it I think is not working though. Here's how my code looks like (I'm not pasting my settings since the rest seems to be working fine):

# In models.py
class E(models.Model):

    title = models.CharField(max_length=200)
    p = models.ForeignKey('P')

class P(models.Model):

    name = models.CharField(max_length=200)

# In views.py
class EViewSet(viewsets.ModelViewSet):

    serializer_class = ESerializer
    queryset = E.objects.all()
    filter_fields = ['p']


class PViewSet(viewsets.ModelViewSet):

    serializer_class = PSerializer
    queryset = P.objects.all()

What I'd like to do is filter all E instances that belong to a certain list of Ps (ie. being able to do http://example.com/v1/e/?p__in=1,2,3 or similar).

The result I'm getting is just all the E objects, unfiltered. I'm not sure if this is supposed to be working but broken or if it's a functionally yet to be added, or maybe I'm just doing it wrong. Sorry I didn't dive in the code to pin point the exact cause of the problem.

Thanks for your help!

@miki725
Copy link
Owner

miki725 commented Feb 24, 2016

sounds like this is related to #14

@miki725
Copy link
Owner

miki725 commented Feb 24, 2016

also I believe this bug, at least partially, should be fixed in 0.3 which is in master branch now however has not been released yet. can you please try using the master branch and let me know if that helps

@catalanojuan
Copy link
Author

@miki725 thanks for your answer! I saw #14 but thought it was only related to exact id matching, that worked for me ok, I think my bug/problem is related to the use of the "in" lookup type. I tried installing the version at master but I'm still unable to make it work.

Thanks!

@miki725
Copy link
Owner

miki725 commented Feb 24, 2016

ok. Ill try to take a closer look when I can.

@miki725 miki725 added the bug label Feb 24, 2016
@jamalex
Copy link

jamalex commented Jun 24, 2016

👍

@miki725
Copy link
Owner

miki725 commented Jan 27, 2017

@catalanojuan sorry for late response.

Im unable to reproduce it.

am using test data from test_project

here is my test url:

http://localhost:8000/many-to-one/reporters/?articles__in=1,2

can successfully query objects via sqlalchemy:

http://localhost:8000/many-to-one/reporters/alchemy/?articles__in=1,2

closing for now. if you still have this issue, please feel free to reopen.

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

No branches or pull requests

3 participants