Repository: flask-admin/flask-admin

Issue:
Do not use column_list to populate column_details_list
The documentation currently states:

```
column_details_list = None
  Collection of the field names included in the details view. If set to None, will get them from the model.
```

which is not true according to the code:

``` python
    def get_details_columns(self):
        """
            Uses `get_column_names` to get a list of tuples with the model
            field name and formatted name for the columns in `column_details_list`
            and not in `column_details_exclude_list`. If `column_details_list`
            is not set, it will attempt to use the columns from `column_list`
            or finally the columns from `scaffold_list_columns` will be used.
        """
        only_columns = (self.column_details_list or self.column_list or
                        self.scaffold_list_columns())
# [...]
```

People who want that behavior can simply write:

``` python
columns_detail_list = details_list = ('foo', 'bar')
```

But avoiding this is much harder.



Discussion:
This was changed in https://github.com/flask-admin/flask-admin/commit/122e064c8665ae815fa5009e690dce1d5e67f68d for issue https://github.com/flask-admin/flask-admin/pull/1268 but I do not think the change and its effects was really thought out.

As it currently is, there are only three ways to get a full list of **all** model columns in the detail view:

* Do not use `column_list` at all -- this is not very helpful since the whole point of having `column_list` is to make it possible to **not** show all model fields by default
* Use both `column_list` and `column_detail_list` and **add all fields that would have been generated through the `scaffold_list_columns` manually**
* Override `get_details_columns` to directly return `self.scaffold_list_colums()`

Any way you slice it, the current behavior of using `column_list` as a default for detail list view does not help at all. If I specify fields in `column_list` they are already visible, so why anyone would then need a detail view with exactly the same details anymore at all?


As a solution, I think https://github.com/flask-admin/flask-admin/commit/122e064c8665ae815fa5009e690dce1d5e67f68d should just be reverted. If there is a problem with Mongo fixed in pymongo instead.

Looking at https://github.com/flask-admin/flask-admin/blob/d7ee730adfc22d878d449fcfcdbdce9bb9ab7bfd/flask_admin/contrib/pymongo/view.py#L121 I think the proper way would be to make that method return `column_list` if it is defined, otherwise give an exception. Preferably even if it returns a valid value you probably should add a logging warning that the programmer really ought to specify `column_detail_list` explicitly. Or something other. Just don't break everything else because pymongo cannot generate scaffold field list...

Resolving patch:
diff --git a/flask_admin/model/base.py b/flask_admin/model/base.py
--- a/flask_admin/model/base.py
+++ b/flask_admin/model/base.py
@@ -856,7 +856,8 @@ def _refresh_cache(self):
         self._sortable_columns = self.get_sortable_columns()
 
         # Details view
-        self._details_columns = self.get_details_columns()
+        if self.can_view_details:
+            self._details_columns = self.get_details_columns()
 
         # Export view
         self._export_columns = self.get_export_columns()
@@ -993,11 +994,12 @@ def get_details_columns(self):
             Uses `get_column_names` to get a list of tuples with the model
             field name and formatted name for the columns in `column_details_list`
             and not in `column_details_exclude_list`. If `column_details_list`
-            is not set, it will attempt to use the columns from `column_list`
-            or finally the columns from `scaffold_list_columns` will be used.
+            is not set, the columns from `scaffold_list_columns` will be used.
         """
-        only_columns = (self.column_details_list or self.column_list or
-                        self.scaffold_list_columns())
+        try:
+            only_columns = self.column_details_list or self.scaffold_list_columns()
+        except NotImplementedError:
+            raise Exception('Please define column_details_list')
 
         return self.get_column_names(
             only_columns=only_columns,


Test patch: