djangosnippets.org: Latest snippets tagged with 'list_display'https://djangosnippets.org/tags/list_display/2013-10-08T03:47:30.909108-05:00Allow foreign key attributes in list_display with '__' - Django 1.5
2013-10-08T03:47:30.909108-05:00kpacnhttps://djangosnippets.org/snippets/2996/<p>Admin for related fields based on: http://djangosnippets.org/snippets/2887/</p>
<p>for Django 1.5 where <strong>metaclass</strong> is deprecated</p>
Freely redistributableAllow foreign key attributes in list_display with '__'
2013-02-03T15:16:56.262958-06:00jcushmanhttps://djangosnippets.org/snippets/2887/<p>This snippet provides a subclass of admin.ModelAdmin that lets you span foreign key relationships in list_display using '__'. The foreign key columns are sortable and have pretty names, and select_related() is set appropriately so you don't need queries for each line.</p>
<p>EDITS:</p>
<ul>
<li>Fixed error when DEBUG=False.</li>
<li>Broke out <code>getter_for_related_field</code> so …</li></ul>
Freely redistributableDynamically insert or append a value to an admin option, e.g. list_display or list_filter
2011-08-22T09:04:23.008278-05:00frankbanhttps://djangosnippets.org/snippets/2521/<p>You can use this function to change an admin option dynamically.</p>
<p>For example, you can add a custom callable to <em>list_display</em> based on request, or if the current user has required permissions, as in the example below:</p>
<pre><code>class MyAdmin(admin.ModelAdmin):
list_display = ('__unicode__', 'other_field')
def changelist_view(self, request, extra_context=None):
if request.user.is_superuser:
add_dynamic_value(self, …</code></pre>
Freely redistributableDRY custom ModelAdmin.list_display methods with a decorator
2008-09-14T09:57:38.489924-05:00exogenhttps://djangosnippets.org/snippets/1056/<p>If you add a lot of custom <code>ModelAdmin</code> methods to <code>list_display</code> like I do, you know it can require a lot of repetition. Notice how adding 'checkbox' to <code>list_display</code> requires typing the method name 4 times:</p>
<pre><code>class ExampleAdmin(admin.ModelAdmin):
list_display = ['checkbox', '__str__']
def checkbox(self, object):
return '<input type="checkbox" value="%s"/>' % …</code></pre>
Freely redistributable