djangosnippets.org: Latest snippets tagged with 'django-admin'https://djangosnippets.org/tags/django-admin/2020-05-21T08:33:35.511673-05:00Automatically setup raw_id_fields ForeignKey & OneToOneField
2020-05-21T08:33:35.511673-05:00agusmakmunhttps://djangosnippets.org/snippets/10813/<p>Automatically setup raw_id_fields ForeignKey & OneToOneField</p>
Freely redistributableAction export django admin to excel exactly as it appears in list-display
2019-10-24T13:42:49.988362-05:00PunisherGuhttps://djangosnippets.org/snippets/10681/<p>I separate this in two files, like this:
export_excel.py and actions.py</p>
<p>I tried to treat all possible forms of information that may appear in admin, such as properties, functions and normal fields, always getting the column name verbose_name or short_description depending on the case.</p>
Freely redistributabledjango admin filter for GenericForeignKey field
2016-04-21T04:27:32.027802-05:00dkoldyaevhttps://djangosnippets.org/snippets/10564/<p>Simple filter for django ModelAdmin</p>
<p>How use:</p>
<pre><code>#models.py
class ObjectWithGenericForeignKey(model.Model):
content_type = models.ForeignKey(ContentType)
object_id = models.PositiveIntegerField()
content_object= GenericForeignKey('content_type', 'object_id', for_concrete_model=False)
#admin.py
class CommentAdmin(admin.ModelAdmin):
list_filter = (get_generic_foreign_key_filter(u'Filter title'),)
</code></pre>
Freely redistributableDynamic upload File type for Gallery Admin
2016-03-18T05:20:59.960292-05:00agusmakmunhttps://djangosnippets.org/snippets/10559/<p>Dynamic upload File type for Gallery Admin</p>
Freely redistributableReadOnly ModelAdmin
2015-07-09T04:37:36.928836-05:00xadamrhttps://djangosnippets.org/snippets/10507/<p>ModelAdmin for readonly in django admin panel</p>
Freely redistributableCreating custom time entries in Django Date widget
2014-05-29T14:39:47.185482-05:00adiqhttps://djangosnippets.org/snippets/3069/<p>jQuery code for making custom list on Admin page in DateTime widget.
Create new js file in your static folder with this code.</p>
<p>To use add custom js to Admin page like this:</p>
<pre><code>class NiceAdmin(admin.ModelAdmin):
class Media:
js = ('js/adminNice.js',)
</code></pre>
<p>This code will change <strong>all</strong> DateTime widgets on selected page.</p>
Freely redistributableAllow 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 redistributableConvert multiple select for m2m to multiple checkboxes in django admin form
2013-04-12T04:12:29.862262-05:00abidibohttps://djangosnippets.org/snippets/2909/<p>This is a javascript to call in the Media class of the ModelAdmin instance for the model, requires some additional css.</p>
<p>The goal of such approach is that the add related functionality is supported, and works also with the django-mptt model fields.</p>
<p>The new component can support resize functionality, in …</p>
Freely redistributableDrag and drop ordering of admin list elements for Grappelli [v2]
2013-01-01T15:24:34.157491-06:00brejochttps://djangosnippets.org/snippets/2870/<p>Adds drag-and-drop ordering of rows in the admin list view for Grappelli. This is a updated version of Snippet <a href="http://djangosnippets.org/snippets/2306/">#2306</a> that works with the current version of Grappelli.</p>
<p>The model needs to have a field holding the position and that field has to be made list_editable in the ModelAdmin. The …</p>
Freely redistributableAutomatically generate admin
2012-12-11T11:37:04.079768-06:00WoLpHhttps://djangosnippets.org/snippets/2862/<p>A management command to automatically generate a fully specified admin for the models in a specific app.</p>
<p>It automatically generates raw_id_fields, search_fields, list_filter and more. It bases this on date fields, fields named as "name" or slug.</p>
<p>Usage: ./manage admin_autogen <model></p>
Freely redistributableDjango Admin Speedup for big tables on postgres
2012-12-02T08:27:17.774113-06:00potiukhttps://djangosnippets.org/snippets/2855/<p>The code is Django 1.4 version of code based on the <a href="http://djangosnippets.org/snippets/2593/">Django 1.3 snippet</a> that speeds up Django's admin pages with postgres back-end for big tables (> few hundred thousands of records).</p>
Freely redistributableLink raw_id_fields (both ForeignKeys and ManyToManyFields) to their change pages
2010-10-04T09:44:54.322975-05:00EmilStenstromhttps://djangosnippets.org/snippets/2217/<p><strong>UPDATE: Now works in Django 1.4</strong></p>
<p>Based on luc_j:s snippet (http://djangosnippets.org/snippets/2108/) to show values in ManyToManyFields in the admin. This snippets does that, but also links each value to its corresponding admin change page.</p>
<p>To use, just set the raw_id_fields to the value you want, and let your form inherit …</p>
Freely redistributableForeignKey filterspec
2010-09-13T09:32:31.406677-05:00luc_jhttps://djangosnippets.org/snippets/2194/<p>Unfortunately, it is not possible currently to use foreign keys in list filter of the admin website. list_filter=['city__country'] doesn't work.</p>
<p>This filter spec tries to workaround this problem.</p>
<p>It is also possible to have 2 filters for a foreign-key field but it requires to add a dummy field to the …</p>
Freely redistributableDisplay user-friendly values of a ManyToManyRawIdWidget
2010-07-15T00:34:28.231746-05:00luc_jhttps://djangosnippets.org/snippets/2108/<p>A Widget for displaying ManyToMany ids in the "raw_id" interface rather than in a <select multiple> box. Display user-friendly value like the ForeignKeyRawId widget</p>
Freely redistributableNumber generator to autofill a field
2010-07-01T07:16:46.170120-05:00piztehttps://djangosnippets.org/snippets/2087/<p><strong>Number format:</strong> number/year</p>
<p><strong>Purpose:</strong> When the user adds a new bill, the "number" field will be automatically filled with the appropriate number.</p>
<ul>
<li>The snippet automatically increments the bill number based in the highest number available. This is because in the use case, the user could start by <em>any</em> number, and …</li></ul>
Freely redistributable