djangosnippets.org: Latest snippets posted by jjdelchttps://djangosnippets.org/users/jjdelc/2011-03-02T22:14:24.247143-06:00jjdelcRandomObjectManager
2011-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.BooleanField()
objects = MyManager()</p>
<p>Now …</p>
Freely redistributableCheap direct_to_tempalte patterns
2008-11-14T16:47:28.117951-06:00jjdelchttps://djangosnippets.org/snippets/1190/<p>Django cheap-pages</p>
<p>Methods to use when you just want to use the Django dispatcher and there will be no extra business logic in your pages.</p>
<p>In some cases flatpages is too flat, and store templates in DB is too much hassle</p>
<pre><code> >>> url(^name/$,
... direct_to_template,
... {'template': 'name.html'},
... name='name') …</code></pre>
Freely redistributable