Commit 8f5ff248 authored by Florian Sachs's avatar Florian Sachs

Inherited PKs for weak objects in sqla

flask_admin.contrib.sqla.tools.is_inherited_primary_key() now works even if the inherited primary key is itself a foreign key. This leads to a better support of SQLAlchemies *joined table inheritance*
parent 40f3580f
...@@ -51,8 +51,9 @@ def is_inherited_primary_key(prop): ...@@ -51,8 +51,9 @@ def is_inherited_primary_key(prop):
:return: Boolean :return: Boolean
:raises: Exceptions as they occur - no ExceptionHandling here :raises: Exceptions as they occur - no ExceptionHandling here
""" """
return (len([column for column in prop.columns if column.primary_key]) == len(prop.columns) and if prop.expression.primary_key:
len([column for column in prop.columns if column.foreign_keys]) == len(prop.columns) - 1) return len(prop._orig_columns) == len(prop.columns)-1
return False
def get_column_for_current_model(prop): def get_column_for_current_model(prop):
""" """
......
...@@ -323,7 +323,7 @@ class ModelView(BaseModelView): ...@@ -323,7 +323,7 @@ class ModelView(BaseModelView):
if is_inherited_primary_key(p): if is_inherited_primary_key(p):
column = get_column_for_current_model(p) column = get_column_for_current_model(p)
else: else:
raise TypeError('Can not convert multiple-column properties (%s.%s)' % (model, p.key)) raise TypeError('Can not convert multiple-column properties (%s.%s)' % (self.model, p.key))
else: else:
# Grab column # Grab column
column = p.columns[0] column = p.columns[0]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment