Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Primary key field name not included in inline models form columns #2282

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions flask_admin/model/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,20 @@ def __init__(self, form_class, pk, form_opts=None, **kwargs):
self.form_opts = form_opts

def get_pk(self):
"""Get the primary key value from the form"""
try:
if isinstance(self._pk, (tuple, list)):
return tuple(getattr(self.form, pk).data for pk in self._pk)

return getattr(self.form, self._pk).data
except AttributeError:
if self._pk not in self.form:
raise AttributeError(
'Primary key field "%s" is required in inline_models "form_columns". Available form fields: %s'
% (self._pk, self.form._fields.keys())
)
raise

if isinstance(self._pk, (tuple, list)):
return tuple(getattr(self.form, pk).data for pk in self._pk)

return getattr(self.form, self._pk).data

def populate_obj(self, obj, name):
for name, field in iteritems(self.form._fields):
Expand Down