A version of http://djangosnippets.org/snippets/2388/ which assumes UTC-based dates.
This is when you store dates in UTC (as you should), and want to display them in your site's local timezone, and you notice that Django's timesince/time template tags still do not support timezones.
A small script that takes a manage.py dumpdata generated json file, and removes fields of the specified models. I needed this because i kept my initial data on a json file and after I removed a field on one of my models, the script wouldn't work anymore.
When using [django debug toolbar](https://github.com/django-debug-toolbar/django-debug-toolbar), I like to be able to turn debugging on and off without having to edit my settings file. This callback makes that possible. Add `?debug=on` to the URL to turn debugging on. It will remain on in the current session until you turn it off with `?debug=off`.
Make sure your session middleware comes before your debug toolbar middleware.
Actually the best way to handle this is to use built-in http://docs.haystacksearch.org/dev/searchqueryset_api.html#load-all
I just missed it while checking documentation and wrote this crappy snippet!
Renders enclosing contents as it is. Useful to avoid tags conflict with certain javascript libraries (eg. jquery-tmpl.js, mustache.js)
Example usage:
`<script class="content-tmpl" type="text/x-jquery-tmpl">`
`{% alien %}`
`{{ tmpl(results) "#results .item-tmpl" }}`
`{% endalien %}`
`</script>`
Here's the python code to produce an admin related widget with the edit and delete link also.
* [RelatedFieldWidgetWrapper](http://djangosnippets.org/snippets/2562)
* [related-widget-wrapper.html](http://djangosnippets.org/snippets/2563)
* [related-widget-wrapper.js](http://djangosnippets.org/snippets/2564)
* [RelatedWidgetWrapperAdmin](http://djangosnippets.org/snippets/2565)
Here's the python code to produce an admin related widget with the edit and delete link also.
* [RelatedFieldWidgetWrapper](http://djangosnippets.org/snippets/2562)
* [related-widget-wrapper.html](http://djangosnippets.org/snippets/2563)
* [related-widget-wrapper.js](http://djangosnippets.org/snippets/2564)
* [RelatedWidgetWrapperAdmin](http://djangosnippets.org/snippets/2565)
To enable "clean url" mode, install [django-pagination](http://code.google.com/p/django-pagination/),
then just add to settings.py
PAGINATION_CLEAN_URL = True
and replace '.../pagination/templatetags/pagination_tags.py' with follow, and so
add to 'pagination/templates/pagination/' folder
pagination_clean_url.html
file, with following code
**Note:**
in urls.py
should be like this:
url(r'^/foo/bar/\d*/?$', foobar_list_handle),
This manager is based on the economical method of randomization. It usable in related models. For support this behavior required to be defined as default manger.
Because select_related() only works on ForeignKeys that are not null or blank, when you are customizing the admin, even if you set "list_select_related=True" you can still end up with way too many querys in the Admin changelist. By adding this code to your model you can decrease the queries dramatically.
I found I needed this when I was working with Django apps with a lot of legacy data and I couldn't set the ForeignKey null=False.
By default the `runserver` command does some magic to automatically serve admin media. This magic doesn't happen when using other servers like gunicorn… But this makes that magic unnecessary by using urls.py to route requests for admin media to the standard static media server.
`#include <production_disclaimer.h>`
This template tag will duplicate its contents according to a variable or integer supplied to it.
{% duplicate 3 %}a{% endduplicate %}
This would return:
> aaa
I have been wrestling with custom app labels and have come to the conclusion that this is the easiest workaround for the problem. Since I name most of my apps as Foo_Bar this makes them look a lot nicer. I just apply the filter to whatever app label and it fixes it.
If you need a more complex replacement, you could just have an if statement that looks for the full app label and replaces it with whatever you want.
This simple snippet provides a more sensible default for the Site object created during the first pass of syncdb (that is, with a default domain of `localhost:8000`). I made this so that the admin's "view on site" button will work automagically during my development cycle (which often involves dropping and recreating a sqlite database).
In addition, it provides 2 options for configuring the default Site as you'd like: settings parameters (`DEFAULT_SITE_DOMAIN` and `DEFAULT_SITE_NAME`) or `kwargs` (the latter takes precedence).
You're looking at the most-bookmarked snippets on the site; if you'd like to help useful snippets show up here, sign up for an account and you'll get your own bookmarks list.