cleaner code + prefer top-level import over _import_class

This commit is contained in:
Stefan Wojcik
2016-12-08 08:18:33 -05:00
parent f6b8899bba
commit 8f657e0f7d
2 changed files with 20 additions and 10 deletions

View File

@@ -714,12 +714,19 @@ class ListField(ComplexBaseField):
def prepare_query_value(self, op, value):
if self.field:
if op in ('set', 'unset', None) and (
not isinstance(value, six.string_types) and
not isinstance(value, BaseDocument) and
hasattr(value, '__iter__')):
# If the value is iterable and it's not a string nor a
# BaseDocument, call prepare_query_value for each of its items.
if (
op in ('set', 'unset', None) and
hasattr(value, '__iter__') and
not isinstance(value, six.string_types) and
not isinstance(value, BaseDocument)
):
return [self.field.prepare_query_value(op, v) for v in value]
return self.field.prepare_query_value(op, value)
return super(ListField, self).prepare_query_value(op, value)