• Florian Sachs's avatar
    Multiple Primary keys for sqla backend · 0ee9e4cb
    Florian Sachs authored
    Flask-Admin can now handle multiple primary keys to some extent. `get_primary_key()` and `get_pk_value()` where the simple, but important changes. When building the url in `list.html` via `url_for` a url with multiple `&id=x&id=y` is built. As the order as preserved and the request args are from type `werkzeug.datastructures.MultiDict`, the multiple PKs can be grabbed in the correct order an push into `get_one()` which actually has no problems with multiple keys, as sqlalchemy's `query.get()` works exactely in this way.
    
    * `contrib.sqla.tools.get_primary_key()` returns a tuple of all primary keys, if there are more than one PKs
    * `contrib.sqla.view.get_pk_value()` returns a tuple with the values of all primary keys, if there are more than one PKs
    * `model.helper.get_mdict_item_or_list()` return the single item of a given MultiDict for the given key or the whole list of items, if there are more than one.
    * `model.base.BaseModelView.[edit_view|delete_view]` can work with a single *id* or multiple ones, by using `get_mdict_item_or_list()`
    * New option `form_excluded_pk_columns_from_unique_validation` for `model.base.BaseModelView` including docstring.
    * Option is evaluated in `contrib.sqla.form.AdminModelConverter.()`
    
    Tests and documentation is included. An example file showing the feature is in `sqla/examples/multiplepk.py`
    
    The changes itself are very small, although it took me hours to go there - the MultiDict saved me! I will change my app I am currently working on to multiple primary keys this week and will push updates if necessary.
    0ee9e4cb
README.rst 47 Bytes