Open Altiire opened 5 years ago
In addition, I had to rewrite create_model
for a special case:
I have a nullable foreign_key of type UUIDType, if the field is not filled in the form, an empty string is sent. This empty string is then parsed by python's uuid.UUID and raise a ValueError exception.
Here is my quick fix:
def create_model(self, form):
try:
model = self.model()
if isinstance(model, models.Supply):
form.populate_obj(model)
self.session.add(model)
self.on_model_change(form, model, True)
model.contact_id = None
self.session.commit()
else:
return super().create_model(form)
except Exception as ex:
if not self.handle_view_exception(ex):
flash(gettext('Failed to create record. %(error)s', error=str(ex)), 'error')
logging.getLogger('flask-admin.sqla').exception('Failed to create record.')
self.session.rollback()
return False
else:
self.after_model_change(form, model, True)
return model
Hi,
I managed to generate forms by overriding the form generation of a ModelView. But before that, I could update my foreign keys with a dropdown on the relationship. I managed to include the foreign keys with the option but I need to manually set their values.
I did not find a solution for a generic based relationship generation under the documentation.
sample of my admin/views.py