Twin column model admin index

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
##############################
place this as your app templates/admin/index.html
######Start snip################
{% extends "admin/base_site.html" %}
{% load i18n %}

{% block stylesheet %}{% load adminmedia %}{% admin_media_prefix %}css/dashboard.css{% endblock %}

{% block extrastyle %}
<style type="text/css">
/* Twin column Django admin layout */
#content-main {
    width: 400px;
}
#content-secondary {
    float: right;
    width: 400px;
    position: relative;
    margin-right: -410px;
}
#content-related {
    width: 215px;
    margin-right: -635px;
}
.dashboard #content {
    width: 400px;
}
</style>
{% endblock %}


{% block coltype %}colMS{% endblock %}
{% block bodyclass %}dashboard{% endblock %}
{% block breadcrumbs %}{% endblock %}
{% block content %}
<div id="content-main">

{% load column_adminapplist %}
{% get_admin_app_list as app_list %}
{% if app_list %}
    {% for app in app_list %}
        {% ifequal app.column 1 %}
            <div class="module">
            <table summary="{% blocktrans with app.name as name %}Models available in the {{ name }} application.{% endblocktrans %}">
            <caption>{% blocktrans with app.name as name %}{{ name }}{% endblocktrans %}</caption>
            {% for model in app.models %}
                <tr>
                {% if model.perms.change %}
                    <th scope="row"><a href="{{ model.admin_url }}">{{ model.name }}</a></th>
                {% else %}
                    <th scope="row">{{ model.name }}</th>
                {% endif %}
    
                {% if model.perms.add %}
                    <td><a href="{{ model.admin_url }}add/" class="addlink">{% trans 'Add' %}</a></td>
                {% else %}
                    <td>&nbsp;</td>
                {% endif %}
    
                {% if model.perms.change %}
                    <td><a href="{{ model.admin_url }}" class="changelink">{% trans 'Change' %}</a></td>
                {% else %}
                    <td>&nbsp;</td>
                {% endif %}
                </tr>
            {% endfor %}
            </table>
            </div>
        {% endifequal %}
    {% endfor %}
{% else %}
    <p>{% trans "You don't have permission to edit anything." %}</p>
{% endif %}
</div>



<div id="content-secondary">
{% if app_list %}
    {% for app in app_list %}
        {% ifequal app.column 2 %}
            <div class="module">
            <table summary="{% blocktrans with app.name as name %}Models available in the {{ name }} application.{% endblocktrans %}">
            <caption>{% blocktrans with app.name as name %}{{ name }}{% endblocktrans %}</caption>
            {% for model in app.models %}
                <tr>
                {% if model.perms.change %}
                    <th scope="row"><a href="{{ model.admin_url }}">{{ model.name }}</a></th>
                {% else %}
                    <th scope="row">{{ model.name }}</th>
                {% endif %}
    
                {% if model.perms.add %}
                    <td><a href="{{ model.admin_url }}add/" class="addlink">{% trans 'Add' %}</a></td>
                {% else %}
                    <td>&nbsp;</td>
                {% endif %}
    
                {% if model.perms.change %}
                    <td><a href="{{ model.admin_url }}" class="changelink">{% trans 'Change' %}</a></td>
                {% else %}
                    <td>&nbsp;</td>
                {% endif %}
                </tr>
            {% endfor %}
            </table>
            </div>
        {% endifequal %}
    {% endfor %}
{% else %}
    <p>{% trans "You don't have permission to edit anything." %}</p>
{% endif %}
</div>
{% endblock %}

{% block sidebar %}
<div id="content-related">
    <div class="module" id="recent-actions-module">
        <h2>{% trans 'Recent Actions' %}</h2>
        <h3>{% trans 'My Actions' %}</h3>
            {% load log %}
            {% get_admin_log 10 as admin_log for_user user %}
            {% if not admin_log %}
            <p>{% trans 'None available' %}</p>
            {% else %}
            <ul class="actionlist">
            {% for entry in admin_log %}
            <li class="{% if entry.is_addition %}addlink{% endif %}{% if entry.is_change %}changelink{% endif %}
              {% if entry.is_deletion %}deletelink{% endif %}">{% if not entry.is_deletion %}<a href="{{ entry.get_admin_url }}">{% endif %}
              {{ entry.object_repr|escape }}{% if not entry.is_deletion %}</a>{% endif %}<br /><span class="mini quiet">
              {% filter capfirst %}{% trans entry.content_type.name %}{% endfilter %}</span></li>
            {% endfor %}
            </ul>
            {% endif %}
    </div>
</div>
{% endblock %}
######End snip##################
end of templates/admin/index.html
##############################


##############################
The next code is for a custom adminapplist.py
Copy django/contrib/admin/templatetags/adminapplist.py 
to your app/templatetags/ directory as column_adminapplist.py
and edit in two places as below:
##############################
# After   has_module_perms = user.has_module_perms(app_label)
# Before  if has_module_perms:
# Paste these four lines into the context (indenting them appropriately):
if hasattr(app, '_admin_index_column'):
    index_column = app._admin_index_column
else:
    index_column = 1
# And in app_list.append({<stuff>}) add
'column': index_column,
# to the dict options.

More like this

  1. Admin Apps Names Translation by Nad/ 4 years, 2 months ago
  2. Admin App/Model Custom Ordering by stephen_mcd 4 years, 1 month ago
  3. reorder apps in admin index by reanes 4 years, 4 months ago
  4. Regrouping admin models by sleytr 6 years, 2 months ago
  5. Subdirectory and subcontext include template tag with examples by t_rybik 4 years ago

Comments

magicrebirth (on April 21, 2009):

is this using the django 1? I don't even have the 'django/contrib/admin/templatetags/adminapplist.py' file.....

#

(Forgotten your password?)