Commit cfdf3cdc authored by Serge S. Koval's avatar Serge S. Koval

Accept classes as InlineFormAdmin configuration instances

parent a9514323
...@@ -96,7 +96,17 @@ def contribute_inline(model, form_class, inline_models): ...@@ -96,7 +96,17 @@ def contribute_inline(model, form_class, inline_models):
elif isinstance(p, BaseModel): elif isinstance(p, BaseModel):
info = InlineFormAdmin(p) info = InlineFormAdmin(p)
else: else:
raise Exception('Unknown inline model admin: %s' % repr(p)) model = getattr(p, 'model', None)
if model is None:
raise Exception('Unknown inline model admin: %s' % repr(p))
attrs = dict()
for attr in dir(p):
if not attr.startswith('_') and attr != model:
attrs[attr] = getattr(p, attr)
info = InlineFormAdmin(model, **attrs)
# Find property from target model to current model # Find property from target model to current model
reverse_field = None reverse_field = None
......
...@@ -348,7 +348,17 @@ def contribute_inline(session, model, form_class, inline_models): ...@@ -348,7 +348,17 @@ def contribute_inline(session, model, form_class, inline_models):
elif hasattr(p, '_sa_class_manager'): elif hasattr(p, '_sa_class_manager'):
info = InlineFormAdmin(p) info = InlineFormAdmin(p)
else: else:
raise Exception('Unknown inline model admin: %s' % repr(p)) model = getattr(p, 'model', None)
if model is None:
raise Exception('Unknown inline model admin: %s' % repr(p))
attrs = dict()
for attr in dir(p):
if not attr.startswith('_') and attr != 'model':
attrs[attr] = getattr(p, attr)
info = InlineFormAdmin(model, **attrs)
# Find property from target model to current model # Find property from target model to current model
target_mapper = info.model._sa_class_manager.mapper target_mapper = info.model._sa_class_manager.mapper
......
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