djangosnippets.org: Latest snippets tagged with 'modeladmin'https://djangosnippets.org/tags/modeladmin/2010-11-18T01:36:14.842657-06:00Django Admin Replacer Code
2010-11-18T01:36:14.842657-06:00riccardodivirgiliohttps://djangosnippets.org/snippets/2269/<p>Ok let's descrive what i have done
I subclassed the django admin to create a form that makes you choose if activate a delete and replace login inside your admin.
</p>
<p>Then i have added a form with a modelChoiceField to make you select another model instance when you are selecting …</p>
Freely redistributableShow users' full names for foreign keys in admin
2009-07-19T19:22:31.477045-05:00SmileyChrishttps://djangosnippets.org/snippets/1642/<p>This is a ModelAdmin base class you can use to make foreign key references to User a bit nicer in admin. In addition to showing a user's username, it also shows their full name too (if they have one and it differs from the username).</p>
<p><strong>2009-08-14</strong>: updated to handle …</p>
Freely redistributableActive User Sorted ModelAdmin
2009-07-02T22:01:54.735118-05:00daemondazzhttps://djangosnippets.org/snippets/1613/<p>Since r7806, the <code>User</code> field is unsorted which makes it harder to find specific users in the list if there is more than a few. This snippet is an <code>django.contrib.admin.ModelAdmin</code> subclass which searches through all of the fields on a form and automatically sorts fields which have a relation with …</p>
Freely redistributablePlay nice with ModelAdmin mixins
2009-01-05T13:02:40.848593-06:00chris.dickinsonhttps://djangosnippets.org/snippets/1278/<p>There are several nice ModelAdmin subclasses that provide useful functionality (such as django-batchadmin, django-reversion, and others), but unfortunately a ModelAdmin can really only subclass one at a time, making them mutually exclusive.</p>
<p>This snippet aims to make mixing these classes in as easy as possible -- you can inherit your …</p>
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 redistributableBind Administration
2008-09-10T18:18:04.587808-05:00ashcrowhttps://djangosnippets.org/snippets/1043/<p>Binds $Model to $ModelAdmin without having to specify each binding manually. The ModelAdmins <strong>must</strong> have the same name as the model (as well as same case) with Admin appended.</p>
<p>Example:
from django.db import models</p>
<pre><code>class SomeModel(models.Model):
name = models.CharField(max_length=255)
class AnotherModel(models.Model):
name = models.CharField(max_length=255)
# bind administration
bind_administration('myproject.myapp.models', 'myproject.myapp.admin')
</code></pre>
Freely redistributable