Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Tree: a04a5f90de
Fetching contributors…

Cannot retrieve contributors at this time

75 lines (52 sloc) 2.209 kB

Django Snippets Cream

Django app packaging the best snippets found on

Included Snippets

963. RequestFactory

Easily create mock request objects for use in testing.

Original Snippet -


from snippetscream import RequestFactory
request = RequestFactory().get('/')

1031. Model Inheritance With Content Type

Supplies a model class aware of its child models, allowing for child class objects to be resolved from parent objects.

Original Snippet -


=== example usage in interpreter ===
>>> from snippetscream import PolyModel
>>> class TrunkModel(PolyModel):
...     pass
>>> class LeafModel(TrunkModel):
...     pass
>>> leaf_obj = LeafModel()
>>> trunk_obj = TrunkModel.objects.get(
>>> trunk_obj
... <TrunkModel: TrunkModel object>
>>> trunk_obj.as_leaf_class()
... <LeafModel: LeafModel object>

1378. Resolve URLs to View Name

Supplies a resolve_to_name function that takes in a path and resolves it to a view name or view function name (given that the path is actually defined in your urlconf).

Original Snippet -


=== urlconf ====
urlpatterns = patterns(''
    (r'/some/url', 'app.views.view'),
    (r'/some/other/url', 'app.views.other.view', {}, 'this_is_a_named_view'),

=== example usage in interpreter ===
>>> from snippetscream import resolve_to_name
>>> print resolve_to_name('/some/url')
>>> print resolve_to_name('/some/other/url')

1875. Auto-create Django Admin User During syncdb

This avoids the frustrating step of having to set up a new admin user every time you re-initialize your database.

Original Snippet -

To enable create the following setting:

Jump to Line
Something went wrong with that request. Please try again.