Snippet List
Manager Mixin to implement get_random() in your models.
You can override get_objects to tune the queriset
To use, define your class:
class MyManager(models.Manager, RandomObjectManager):
DEFAULT_NUMBER = 5 # I can change that
def get_objects(self):
return self.filter(active=True) # Only active models plz
class MyModel(models.Model):
active = models.BooleanField()
objects = MyManager()
Now you can do:
MyModel.objects.get_random()
Django cheap-pages
Methods to use when you just want to use the Django dispatcher and there will be no extra business logic in your pages.
In some cases flatpages is too flat, and store templates in DB is too much hassle
>>> url(^name/$,
... direct_to_template,
... {'template': 'name.html'},
... name='name')
can be expressed as:
>>> page('name')
urlpatterns = patterns('', ...)
urlpatterns += build('Regexp', ['page1', 'page2', ...])
- generic
- urlpatterns
- direct_to_template
jjdelc has posted 2 snippets.