philipn / django-rest-framework-filters

Better filtering for Django REST Framework
Other
848 stars 130 forks source link

Circular RelatedFilter configuration? Impossible? #48

Closed mlissner closed 8 years ago

mlissner commented 8 years ago

I have a database of judges each of whom have degrees from specific schools.

I want to use my API to either query judges that went to a specific school:

/api/judges/?educations__school_name=vanderbilt

Or I want to filter which judges went to a specific school:

/api/schools/?judges__race=black

I can set up a RelatedFilter on one of these, but when I set it up on the second one, it can't find the class.

This problem is handled in Django models by allowing strings for ForeignKey names:

 appointer = models.ForeignKey(
    'Politician',
)

Is there a way to do this with Django filters?

Thanks for the great package.

mlissner commented 8 years ago

Following up to this, I'm trying this for a separate model and realizing that it doesn't work because of circular import errors between to filters.py files that I've created (one for each model).

Seems like a big gap, so I'm hopeful that there's a way to make this work.

philipn commented 8 years ago

Did you see the information at the end of the readme on recursive filters? E.g. filters.RelatedFilter('people.views.PersonFilter', name='best_friend')

If this stopped working then it may be a regression.

On Dec 21, 2015, at 3:01 PM, Mike Lissner notifications@github.com wrote:

Following up to this, I'm trying this for a separate model and realizing that it doesn't work because of circular import errors between to filters.py files that I've created (one for each model).

Seems like a big gap, so I'm hopeful that there's a way to make this work.

— Reply to this email directly or view it on GitHub.

mlissner commented 8 years ago

I feel like an idiot. I looked everywhere for this answer. Except the readme, dang it. Anyway, PR sent to tweak the readme. I figure if I screwed this up, other people will too.