From 3fa18d32d991281cfdd98c405ac6fb18b0314f82 Mon Sep 17 00:00:00 2001 From: fanchi Date: Wed, 4 Jul 2018 18:32:08 +0300 Subject: [PATCH] Add method to check instance types of field and its inner fields --- src/infi/clickhouse_orm/fields.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/infi/clickhouse_orm/fields.py b/src/infi/clickhouse_orm/fields.py index 8fd8a6e..8580bb8 100644 --- a/src/infi/clickhouse_orm/fields.py +++ b/src/infi/clickhouse_orm/fields.py @@ -79,6 +79,22 @@ class Field(object): else: return self.db_type + def isinstance(self, types): + """ + Checks if the instance if one of the types provided or if any of the inner_field child is one of the types + provided, returns True if field or any inner_field is one of ths provided, False otherwise + :param types: Iterable of types to check inclusion of instance + :return: Boolean + """ + if isinstance(self, types): + return True + inner_field = getattr(self, 'inner_field', None) + while inner_field: + if isinstance(inner_field, types): + return True + inner_field = getattr(self, 'inner_field', None) + return False + class StringField(Field):