Python django_filters.FilterSet() Examples
The following are 8
code examples of django_filters.FilterSet().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
django_filters
, or try the search function
.
Example #1
Source File: test_free_text_filter.py From adhocracy4 with GNU Affero General Public License v3.0 | 5 votes |
def test_free_text_filter_exception(): with pytest.raises(ImproperlyConfigured): class SearchFilterSet(django_filters.FilterSet): search = FreeTextFilter( # no fields set ) class Meta: model = question_models.Question fields = ['search']
Example #2
Source File: test_fields.py From graphene-django with MIT License | 5 votes |
def test_filter_filterset_class_filter_fields_exception(): with pytest.raises(Exception): class ReporterFilter(FilterSet): class Meta: model = Reporter fields = ["first_name", "articles"] class ReporterFilterNode(DjangoObjectType): class Meta: model = Reporter interfaces = (Node,) filterset_class = ReporterFilter filter_fields = ["first_name", "articles"]
Example #3
Source File: test_fields.py From graphene-django with MIT License | 5 votes |
def test_filter_filterset_class_information_on_meta(): class ReporterFilter(FilterSet): class Meta: model = Reporter fields = ["first_name", "articles"] class ReporterFilterNode(DjangoObjectType): class Meta: model = Reporter interfaces = (Node,) filterset_class = ReporterFilter field = DjangoFilterConnectionField(ReporterFilterNode) assert_arguments(field, "first_name", "articles") assert_not_orderable(field)
Example #4
Source File: test_fields.py From graphene-django with MIT License | 5 votes |
def test_filter_filterset_class_information_on_meta_related(): class ReporterFilter(FilterSet): class Meta: model = Reporter fields = ["first_name", "articles"] class ArticleFilter(FilterSet): class Meta: model = Article fields = ["headline", "reporter"] class ReporterFilterNode(DjangoObjectType): class Meta: model = Reporter interfaces = (Node,) filterset_class = ReporterFilter class ArticleFilterNode(DjangoObjectType): class Meta: model = Article interfaces = (Node,) filterset_class = ArticleFilter class Query(ObjectType): all_reporters = DjangoFilterConnectionField(ReporterFilterNode) all_articles = DjangoFilterConnectionField(ArticleFilterNode) reporter = Field(ReporterFilterNode) article = Field(ArticleFilterNode) schema = Schema(query=Query) articles_field = ReporterFilterNode._meta.fields["articles"].get_type() assert_arguments(articles_field, "headline", "reporter") assert_not_orderable(articles_field)
Example #5
Source File: test_fields.py From graphene-django with MIT License | 5 votes |
def test_global_id_field_explicit(): class ArticleIdFilter(django_filters.FilterSet): class Meta: model = Article fields = ["id"] field = DjangoFilterConnectionField(ArticleNode, filterset_class=ArticleIdFilter) filterset_class = field.filterset_class id_filter = filterset_class.base_filters["id"] assert isinstance(id_filter, GlobalIDFilter) assert id_filter.field_class == GlobalIDFormField
Example #6
Source File: test_fields.py From graphene-django with MIT License | 5 votes |
def test_global_id_multiple_field_explicit(): class ReporterPetsFilter(django_filters.FilterSet): class Meta: model = Reporter fields = ["pets"] field = DjangoFilterConnectionField( ReporterNode, filterset_class=ReporterPetsFilter ) filterset_class = field.filterset_class multiple_filter = filterset_class.base_filters["pets"] assert isinstance(multiple_filter, GlobalIDMultipleChoiceFilter) assert multiple_filter.field_class == GlobalIDMultipleChoiceField
Example #7
Source File: test_fields.py From graphene-django with MIT License | 5 votes |
def test_global_id_multiple_field_explicit_reverse(): class ReporterPetsFilter(django_filters.FilterSet): class Meta: model = Reporter fields = ["articles"] field = DjangoFilterConnectionField( ReporterNode, filterset_class=ReporterPetsFilter ) filterset_class = field.filterset_class multiple_filter = filterset_class.base_filters["articles"] assert isinstance(multiple_filter, GlobalIDMultipleChoiceFilter) assert multiple_filter.field_class == GlobalIDMultipleChoiceField
Example #8
Source File: test_fields.py From graphene-django with MIT License | 4 votes |
def test_filter_shortcut_filterset_context(): class ArticleContextFilter(django_filters.FilterSet): class Meta: model = Article exclude = set() @property def qs(self): qs = super(ArticleContextFilter, self).qs return qs.filter(reporter=self.request.reporter) class Query(ObjectType): context_articles = DjangoFilterConnectionField( ArticleNode, filterset_class=ArticleContextFilter ) r1 = Reporter.objects.create(first_name="r1", last_name="r1", email="r1@test.com") r2 = Reporter.objects.create(first_name="r2", last_name="r2", email="r2@test.com") Article.objects.create( headline="a1", pub_date=datetime.now(), pub_date_time=datetime.now(), reporter=r1, editor=r1, ) Article.objects.create( headline="a2", pub_date=datetime.now(), pub_date_time=datetime.now(), reporter=r2, editor=r2, ) class context(object): reporter = r2 query = """ query { contextArticles { edges { node { headline } } } } """ schema = Schema(query=Query) result = schema.execute(query, context_value=context()) assert not result.errors assert len(result.data["contextArticles"]["edges"]) == 1 assert result.data["contextArticles"]["edges"][0]["node"]["headline"] == "a2"