How to change input data from GUI/request in Flask admin before it converted in form? In case edit/create model

136 views Asked by At

Env:

python 2.7.x
Flask-Admin==1.5.3
db - mongo(not necessory)

View in admin:

class AView(ModelView):
    can_create = True
    can_edit = True
    can_delete = True

    column_editable_list = []
    column_list = ['some_ReferenceField_in_ListField']
    column_searchable_list = []

    form_ajax_refs = {
        'some_ReferenceField_in_ListField': {
            'fields': ['some_field']
        }
    }

Case:

GUI sends requestin for edit model (via admin page) and put list of some values into 'some_ReferenceField_in_ListField' field.(just as an example). This request would look like:
curl 'https://<host>/admin/model_name/edit/?url=<some_querystring>' -H 'content-type: multipart/form-data; boundary=----some boundary'--data-binary $'Content-Disposition: form-data; name="some_ReferenceField_in_ListField"\r\n\r\nsome_data__here\r\n------'

Question:

Which method I should override to change some_data__here in field some_ReferenceField_in_ListField before it is passed to <view_instance>.form?

PS:

Actually I need to replace values with IDs for newly created object(but don't ask me why I need that weird thing). Coz if form is already and I'll try to reach data from form like self.form.some_ReferenceField_in_ListField.data Flask will raise an exception like ValidationError: u'rgdrgdrg' is not a valid ObjectId, it must be a 12-byte input or a 24-character hex string and it's expected, coz rgdrgdrg is not mongoDB's ID format. But it's lyrics.

PSS:

I would expect some self.request object like in Django. :)

0

There are 0 answers