Created
March 29, 2017 14:49
-
-
Save kezabelle/d6ae5e69366f56e6411633ad69050643 to your computer and use it in GitHub Desktop.
django-filters .. paring down the choices in a related widget.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django_filters import FilterSet | |
class MyModelFilterSet(FilterSet): | |
class Meta: | |
model = MyModel | |
fields = ['my_relation'] # internally this is a reverse relation, so MyModelInstance.my_relation_set.all() | |
# How do I get it so that the ModelChoiceFilter (actually a ModelMultipleChoiceFilter!) is only | |
# those items which exist given the FilterSet's original queryset (self.queryset.all()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ended up doing it in the filterset's init method. Bit nasty, but it works.