From 7756cef79138c404d363ca21ffa9a91a9418cf00 Mon Sep 17 00:00:00 2001 From: Abdeldjalil Hezouat Date: Tue, 27 Sep 2022 21:57:48 +0100 Subject: [PATCH 1/3] allow fk field filtering python style --- ormar/queryset/field_accessor.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ormar/queryset/field_accessor.py b/ormar/queryset/field_accessor.py index b27483771..bf7cff2fa 100644 --- a/ormar/queryset/field_accessor.py +++ b/ormar/queryset/field_accessor.py @@ -71,9 +71,9 @@ def __getattr__(self, item: str) -> Any: return object.__getattribute__(self, item) # pragma: no cover def _check_field(self) -> None: - if not self._field: + if not self._field and not self._access_chain in self._source_model.Meta.table.columns.keys(): raise AttributeError( - "Cannot filter by Model, you need to provide model name" + "Cannot filter by M2M field, you need to provide model name" ) def _select_operator(self, op: str, other: Any) -> FilterGroup: From 007fdf243276084865e39c2f65be23458184de76 Mon Sep 17 00:00:00 2001 From: Abdeldjalil Hezouat Date: Thu, 29 Sep 2022 23:18:54 +0100 Subject: [PATCH 2/3] format code --- ormar/queryset/field_accessor.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ormar/queryset/field_accessor.py b/ormar/queryset/field_accessor.py index bf7cff2fa..1b720b388 100644 --- a/ormar/queryset/field_accessor.py +++ b/ormar/queryset/field_accessor.py @@ -71,7 +71,10 @@ def __getattr__(self, item: str) -> Any: return object.__getattribute__(self, item) # pragma: no cover def _check_field(self) -> None: - if not self._field and not self._access_chain in self._source_model.Meta.table.columns.keys(): + if ( + not self._field + and not self._access_chain in self._source_model.Meta.table.columns.keys() + ): raise AttributeError( "Cannot filter by M2M field, you need to provide model name" ) From 9a2d2b0a8d26d615ebedba738595fdd209583591 Mon Sep 17 00:00:00 2001 From: Abdeldjalil Hezouat Date: Thu, 29 Sep 2022 23:34:24 +0100 Subject: [PATCH 3/3] update tests --- tests/test_model_definition/test_fields_access.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_model_definition/test_fields_access.py b/tests/test_model_definition/test_fields_access.py index 5140b3e54..cee1af217 100644 --- a/tests/test_model_definition/test_fields_access.py +++ b/tests/test_model_definition/test_fields_access.py @@ -79,7 +79,7 @@ def test_fields_access(): assert curr_field._source_model == PriceList with pytest.raises(AttributeError): - assert Product.category >= 3 + assert Category.price_lists >= 3 @pytest.mark.parametrize(