djangosnippets.org: Latest snippets tagged with 'ordering'https://djangosnippets.org/tags/ordering/2013-08-12T21:30:02.634074-05:00Many 2 Many Admin Ordering with Mysql
2013-08-12T21:30:02.634074-05:00visik7https://djangosnippets.org/snippets/2979/<p>My Models has a FK to translations and also a many 2 many to categories which also them are translated</p>
<p>With this code I concatenate the translation of the categories and allow the changelist to order them.</p>
<p>works only on mysql but you can adapt to your DB</p>
<p>SET SESSION …</p>
Freely redistributableSophisticated order_by sorting
2012-12-10T09:53:28.937935-06:00mawihttps://djangosnippets.org/snippets/2861/<p>I wanted to sort a CharField which consists of digits in a different way. This field is a matricle number field (some kind of registration number for students. They have matricle numbers in the format YYxxxxxx - which means "YY" are the last two digits of the year they started …</p>
Freely redistributableDjango admin inline ordering - javascript only implementation
2012-12-05T06:32:16.151110-06:00ojhilthttps://djangosnippets.org/snippets/2858/<p>Having spent ages trying out various admin inline ordering packages and examples I found on here and elsewhere I failed to find a single one that did what I was after in the way I wanted or that worked, so I wrote one!</p>
<p>The general idea for this version was …</p>
Freely redistributableDjango Admin Index Custom App & Model Ordering
2011-11-27T14:46:48.204390-06:00hschttps://djangosnippets.org/snippets/2613/<p>This templatetag was inspired by: <a href="http://djangosnippets.org/snippets/1939/">Admin App/Model Custom Ordering</a>.</p>
<p>I rewrote it from scratch because it wasn't working on my install.</p>
Freely redistributableDisable ordering in the admin for a model
2011-10-26T08:00:07.080676-05:00flupkehttps://djangosnippets.org/snippets/2580/<p>Django admin orders models by their primary key by default, which can be undesirable on very large tables.</p>
<p>This shows how to disable any ordering on a model.</p>
<p>Note that this behavior is fixed in 1.4 trunk.</p>
Freely redistributableAdmin: ordering by multiple fields in a column sort
2010-07-16T02:19:03.678871-05:00benatkinhttps://djangosnippets.org/snippets/2110/<p>The new changelist supports clicking on a column header to order by that column, like iTunes. Unlike iTunes, which sorts by track number if you click the Artist or Album column header, it can only order by the column clicked on. By adding a property to my ModelAdmin, and subclassing …</p>
Freely redistributableAjax ordering models on the change list page of the admin using drag and drop with jQuery UI
2010-06-01T09:50:44.178823-05:00spoofhttps://djangosnippets.org/snippets/2047/<p>Makes models orderable on the change list page of the admin using drag and drop with jQuery UI (via sortable()). So you can order your objects in more easy way.</p>
<p>Inspired by snippets <a href="http://djangosnippets.org/snippets/1053/">#1053</a> and <a href="http://djangosnippets.org/snippets/998/">#998</a></p>
<p>First, ordering field to your model (default called 'order). You can specify other name …</p>
Freely redistributableAdmin App/Model Custom Ordering
2010-02-24T17:42:46.967461-06:00stephen_mcdhttps://djangosnippets.org/snippets/1939/<p>This combination of settings.py admin_reorder_tag.py and admin/base_site.html gives you the ability to define custom ordering for the apps and models in the admin app.</p>
<ol>
<li>
<p>Add the setting ADMIN_REORDER to your settings.py as a tuple with each item containing a tuple of the app name and a tuple of the models …</p></li></ol>
Freely redistributableDynamic tabular inlines with optional drag-n-drop sorting
2009-05-05T15:44:41.360837-05:00Aneonhttps://djangosnippets.org/snippets/1489/<p>This jQuery javascript enables dynamic add/delete of rows in tabular inlines. It adds a "+" icon at the bottom of the inline to allow addition of new rows, and replaces the default delete checkbox with a "x" icon for deletion, giving you the possibility to add/delete rows instantly without reloading …</p>
Freely redistributableMoving items up/down from the admin interface
2008-09-05T03:49:56.575707-05:00vicoxhttps://djangosnippets.org/snippets/1025/<p>Move Items up and down from the admin interface. Like phpBB does it with its forums.</p>
<p>An additional select field is added to the admin form. After the model has been saved, a model method is called (with the value of the new field), which handles the reordering.</p>
<p>A more …</p>
Freely redistributableOrdering a queryset by _CHOICES
2008-07-21T16:52:07.940260-05:00gkellyhttps://djangosnippets.org/snippets/902/<p>I recently needed to sort a list of objects by cardinal direction clock-wise. Since this is different than alphabetical, and I didn't want to use a dictionary to map to integers, here is what I came up with.</p>
<p>There may be a cleaner way to do this by overriding some …</p>
Freely redistributablePositionField
2008-07-15T13:50:02.027313-05:00jpwattshttps://djangosnippets.org/snippets/884/<p><strong>This is a model field for managing user-specified positions.</strong></p>
<h1>Usage</h1>
<p>Add a <code>PositionField</code> to your model; that's just about it.</p>
<p>If you want to work with all instances of the model as a single collection, there's nothing else required. In order to create collections based on another field in the …</p>
Freely redistributable