djangosnippets.org: Latest snippets tagged with 'random'https://djangosnippets.org/tags/random/2015-02-25T15:51:23.691037-06:00Seeded Randomized Querysets w/ Pagination Mixin2015-02-25T15:51:23.691037-06:00ScottBarkmanhttps://djangosnippets.org/snippets/10468/<p>Mixin to support pagination when randomizing querysets. </p>
<p>Requirements: Postgres, Django Sessions</p>
<p>Note: This shouldn't be used on large complex datasets. It utilizes the relatively slow method of '?' randomized sorting. Use with caution. </p>
<p>Todo: MySQL support, Support for larger datasets</p>
Freely redistributableSimple random file CAPTCHA2012-03-07T19:36:32.048705-06:00jeverlinghttps://djangosnippets.org/snippets/2710/<p>This is a snippet for a simple CAPTCHA. A random image from a list of images is shown, and the form checks if the correct solution was given.<br />
Normally I would use django-simple-captcha or maybe reCAPTCHA, but in this case I wanted to have a number of fixed images, nothing ...</p>
Freely redistributableRandom object IDs using an abstract base model2011-07-15T06:25:15.057845-05:00elverhttps://djangosnippets.org/snippets/2490/<p>To put obfuscated primary keys in any class, simply inherit from this one. For example:</p>
<p>class Offer(ObfuscatedPKModel)</p>
<p>You can match for these bigint primary keys in your urls.py like this:</p>
<p>'^offer/(?P&lt;offer_pk&gt;[0-9-]+)$'</p>
Freely redistributableRandomObjectManager2011-03-02T22:14:24.247143-06:00jjdelchttps://djangosnippets.org/snippets/2380/<p>Manager Mixin to implement get_random() in your models.
You can override get_objects to tune the queriset</p>
<p>To use, define your class:</p>
<p>class MyManager(models.Manager, RandomObjectManager):
DEFAULT_NUMBER = 5 # I can change that</p>
<pre><code>def get_objects(self):
return self.filter(active=True) # Only active models plz
</code></pre>
<p>class MyModel(models.Model):
active = models ...</p>
Freely redistributableTemplate Tag for Random Selection of Any Line2010-07-22T20:59:25.294321-05:00drhodenhttps://djangosnippets.org/snippets/2121/<p>These are template tags meant to support the construction of text in a random or seeded random (reproducible) way. Two tags are provided: <code>seed_randomization</code> and <code>any</code>.
</p>
<p>Only seed the randomization if you wish to have the options generated the same way each time. Only necessary once per request, if done ...</p>
Freely redistributableGenerate Model Data. Lots of Options.2010-03-25T02:14:13.741665-05:00bl4th3rsk1t3https://djangosnippets.org/snippets/1969/<p>Generate model data with this django management command!
</p>
<p>Data is generated based off of the model field types. And will also correctly generate foreign key's to other randomly generated records for join tables. And generate images with random colors and random words in the image - for image fields.
</p>
<p>You ...</p>
Freely redistributableSlideshow (Random Image Display) - Using Jquery2009-07-25T11:02:47.490762-05:00veeravendhanhttps://djangosnippets.org/snippets/1652/<p>The above code contains the file name fetches random images from the database.
Using the JQuery this image is displayer in the page</p>
Freely redistributableSometimes Tag2009-06-01T22:59:57.973509-05:00deadwisdomhttps://djangosnippets.org/snippets/1545/<p>Adds a templatetag that works like an if block, but . The one and only argument is a float that reflects the percentage chance. It defaults to .2, %20.</p>
<p>{% sometimes %}
&lt;img src='spy_behind_sniper.jpg'/&gt;
{% else %}
&lt;img src='sniper.jpg'/&gt;
{% endsometimes %}</p>
<p>-- or --</p>
<p>{% sometimes .001 %}
You win!
{% else %}
Sorry, not a ...</p>
Freely redistributableRandomized Include Tag2008-12-05T10:51:36.275744-06:00justinlillyhttps://djangosnippets.org/snippets/1233/<p>a randomized version of {% include %}</p>
<p>{% rand_include "foo.html","bar.html","zot.html" %}</p>
Freely redistributableModel with random ID2008-06-18T14:22:24.562778-05:00jobs@flowgram.comhttps://djangosnippets.org/snippets/814/<p>An abstract model base class that gives your models a random base-32 string ID. This can be useful in many ways. Requires a Django version recent enough to support model inheritance.</p>
Freely redistributableRandom Quotes2007-06-14T13:43:28.151797-05:00ferretsrulehttps://djangosnippets.org/snippets/286/<p>Display a random quote. Just add some quotes to the app (you may want to add the administration interface options) and then load the template tag:
<code>{% load random_quote %}</code>
and then call the tag to display a random quote from the app
<code>{% random_quote %}</code></p>
<p>feel free to improve it/whatever..</p>
<p>:)</p>
Freely redistributableRandom-image template tag2007-04-01T09:15:16.096982-05:00pbxhttps://djangosnippets.org/snippets/150/<p>This tag makes it easy to have a random rotation of images on a page. Don't forget to set your MEDIA_URL.</p>
Freely redistributable