Skip to content

Commit

Permalink
Merge pull request #2393 from alanhamlett/master
Browse files Browse the repository at this point in the history
Use isinstance instead of comparing class type
  • Loading branch information
alanhamlett authored Oct 15, 2023
2 parents 955e4ee + df6b596 commit 0ede39d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
14 changes: 5 additions & 9 deletions flask_admin/contrib/mongoengine/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,17 +320,13 @@ def scaffold_list_columns(self):
columns = []

for n, f in self._get_model_fields():
# Verify type
field_class = type(f)

if (field_class == mongoengine.ListField and
isinstance(f.field, mongoengine.EmbeddedDocumentField)):
if isinstance(f, mongoengine.ListField) and isinstance(f.field, mongoengine.EmbeddedDocumentField):
continue

if field_class == mongoengine.EmbeddedDocumentField:
if isinstance(f, mongoengine.EmbeddedDocumentField):
continue

if self.column_display_pk or field_class != mongoengine.ObjectIdField:
if self.column_display_pk or not isinstance(f, mongoengine.ObjectIdField):
columns.append(n)

return columns
Expand All @@ -343,7 +339,7 @@ def scaffold_sortable_columns(self):

for n, f in self._get_model_fields():
if type(f) in SORTABLE_FIELDS:
if self.column_display_pk or type(f) != mongoengine.ObjectIdField:
if self.column_display_pk or not isinstance(f, mongoengine.ObjectIdField):
columns[n] = f

return columns
Expand Down Expand Up @@ -467,7 +463,7 @@ def _search(self, query, search_term):
criteria = None

for field in self._search_fields:
if type(field) == mongoengine.ReferenceField:
if isinstance(field, mongoengine.ReferenceField):
import re
regex = re.compile('.*%s.*' % term)
else:
Expand Down
9 changes: 3 additions & 6 deletions flask_admin/contrib/peewee/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,9 @@ def scaffold_list_columns(self):
columns = []

for n, f in self._get_model_fields():
# Verify type
field_class = type(f)

if field_class == ForeignKeyField:
if isinstance(f, ForeignKeyField):
columns.append(n)
elif self.column_display_pk or field_class != PrimaryKeyField:
elif self.column_display_pk or not isinstance(f, PrimaryKeyField):
columns.append(n)

return columns
Expand All @@ -208,7 +205,7 @@ def scaffold_sortable_columns(self):
columns = dict()

for n, f in self._get_model_fields():
if self.column_display_pk or type(f) != PrimaryKeyField:
if self.column_display_pk or not isinstance(f, PrimaryKeyField):
columns[n] = f

return columns
Expand Down

0 comments on commit 0ede39d

Please sign in to comment.