djangosnippets.org: Latest snippets tagged with 'lookup'http://djangosnippets.org/tags/lookup/2010-08-04T16:09:10.326913-05:00Query lookups using operators
2010-08-04T16:09:10.326913-05:00divermanhttp://djangosnippets.org/snippets/2135/<p>This class emulates query lookups to behave as numeric operators. Inspired by SQLAlchemy.
</p>
<pre><code>User.objects.filter( X('username') == 'diverman' )
User.objects.filter( X('username') != 'diverman' )
User.objects.filter( X('pk') > 10 )
User.objects.filter( X('pk') >= 10 )
User.objects.filter( X('pk') < 10 )
User.objects.filter( X('pk') <= 10 )
User.objects.filter( X('username') % 'iverma' )
User.objects.filter( X('username') …</code></pre>
Freely redistributableAdmin Hack: Quick lookup of GenericForeignKey id by ContentType
2008-09-25T22:14:16.362744-05:00adnanhttp://djangosnippets.org/snippets/1085/<p>Generic Relations with django.contrib.contenttypes.generic.GenericForeignKey work well for models but the admin interface just shows the object id as an integer with no easy way to lookup the id of a new object. This jquery javascript adds a "Lookup <ContentType Name>" link next to the object id field in the admin …</p>
Freely redistributableLazily lookup dynamically for templates
2008-03-08T14:32:31.506540-06:00axiakhttp://djangosnippets.org/snippets/632/<p>If you've ever wanted to dynamically lookup values in the template layer (e.g. <code>dictionary[bar]</code>), then you've probably realized/been told to do this in the python layer. The problem is then you often to build a huge 2-D list to hold all of that data.</p>
<p>These are two solutions to …</p>
Freely redistributableCached lookup model mixin
2008-01-22T15:55:55.663896-06:00isagalaevhttp://djangosnippets.org/snippets/560/<p>This mixin is intended for small lookup-style models that contain mostly static data and referenced by foreign keys from many other places. A good example is a list of Payment options in an e-shop that is referenced from Orders and is hitting database <code>order.payment</code> at least one time for an …</p>
Freely redistributable