question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

New feature in details view

See original GitHub issue

I was playing around with details view in my admin panel and thought that it would be nice to have ability to group data for viewing convenience. Is this kind of feature wanted in flask-admin? If so I could make it.

Code example:

def get_columns_grouped():
    d = OrderedDict() #using ordered dict for strict ordering
    d['Main'] = ('user', 'status', 'created_at')
    d['Private'] = ('ssn', 'dob', 'dl_state', 'dl_number', 'sex')
    d['Financial Info'] = ('account', 'routing')
    d['Billing Address'] = ('address', 'city', 'state', 'zip')
    return d

class AccountModelView(SecureModelView):
    details_grouped = True
    details_columns_grouped = get_columns_grouped()

I’m attaching a screenshot so you can better understand what I’m talking about. screen shot 2015-08-04 at 5 37 47 pm

Versus

screen shot 2015-08-04 at 5 38 25 pm

Issue Analytics

  • State:open
  • Created 8 years ago
  • Comments:38 (26 by maintainers)

github_iconTop GitHub Comments

2reactions
macfirecommented, Apr 10, 2019
class AccountModelView(SecureModelView):

   def get_details_grouped():
        d = {
            'main': {
                'user',
                'status',
                'created_at'
            },
            'billing_address': {
                'address',
                'city',
                'state',
                'zip'
            }
        }
        
        return d

details template:


    {% block details_table %}
      
      <table class="table">

        {% for group in admin_view.get_details_grouped() %}

          <tbody>
          <tr>
            <th colspan="2">{{ group  | capitalize }}</th>
          </tr>
          {% for i in admin_view.get_details_grouped()[group] %}
            <tr>
              <td class="field-name">
                <b>{{ i | replace("_", " ") | capitalize }}</b>
              </td>
              <td>
                {{ get_value(model, i) }}
              </td>
            </tr>
          {% endfor %}

          </tbody>
        {% endfor %}

      </table>

     {% endblock %}

Update: Of course, if needed, use OrderedDict as OP recommends.

 d = OrderedDict() #using ordered dict for strict ordering
    d['main'] = ('user', 'status', 'created_at')
    d['billing_address'] = ('address', 'city', 'state', 'zip')
    return d
1reaction
macfirecommented, Apr 9, 2019

This can be currently implemented by using declaring a method in at the view class which returns an dict, then accessing dict via admin_view variable in the template :

class AccountModelView(SecureModelView):

   def get_details_grouped():
    d = OrderedDict() #using ordered dict for strict ordering
    d['Main'] = ('user', 'status', 'created_at')
    d['Private'] = ('ssn', 'dob', 'dl_state', 'dl_number', 'sex')
    d['Financial Info'] = ('account', 'routing')
    d['Billing Address'] = ('address', 'city', 'state', 'zip')
    return d
{{ admin_view.get_details_grouped()['Main'].user }}
Read more comments on GitHub >

github_iconTop Results From Across the Web

iOS 16 - New Features - Apple
See all the latest features, enhancements, app updates, and more in iOS 16 for ... Choose to view notifications on the Lock Screen...
Read more >
Windows 11 New File Explorer Experience New Features ...
This post will learn about Windows 11 new file explorer experience design details. There are several new design changes in the Windows 11 ......
Read more >
Build a details view - Android Developers
Creating an activity for your details view, separate from the browse activity, enables you to invoke your details view using an Intent ....
Read more >
What's new in recent Windows updates - Microsoft Support
See what's new in recent Windows 10 and Windows 11 updates, including a chat from the taskbar, widgets, snap groups, and more.
Read more >
How To Find Details on New Microsoft 365 Features - YouTube
The links in their Weekly Digest are no longer functional so if you click VIEW MORE admin.microsoft.com will open but the sidebar with ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found