Just add it in templatetags/delicious.py
In your template:
<h3>Del.icio.us</h3>
<ul class="list">
{% load delicious %}
{% load_delicious_links %}
{% for link in delicious_links %}
<li><a href="{{link.link}}">{{link.title|safe}}</a></li>
{% endfor %}
</ul>
Handles exceptions from AJAX code, giving more useful errors and tracebacks.
(By the way, all these new snippets are extracts from [django-webapp](http://code.google.com/p/django-webapp/).)
This exact code is not well tested, but it's refactored from some code we use in production.
A simple InlineModelAdmin class that enables you to edit models that are bound by the instance via a generic foreign key (`content_type`, `object_id` pair)
Use like:
class PlacementInlineOptions( generic.GenericTabularInline ):
model = Placement
extra = 2
ct_field_name = 'target_ct'
id_field_name = 'target_id'
Can be also found at #4667
This snippet adds a select language drop down menu in the admin bar (just after Documentation link).
For this approach it's necessary to copy from admin templates the admin/base.html to the project templates (keeping the admin directory), changing just line 25 ad shown. Then it's necessary to create specified admin/change_language.html template.
This code works like that in the Google Groups you see and when try to see an e-mail and it is like this "[email protected]" with a link to write a captcha code and see the true value.
You can use it for anything you want: links, blocks of texts, block of HTML, etc.
To use in your template, place the a code like this (remember to load the template tags file with a {% load file_name %} before):
{% protectantirobots %}
<a href="mailto: {{ office.email }}">{{ office.email }}</a>
{% endprotectantirobots %}
You can also use **django-plus** application to do this:
[http://code.google.com/p/django-plus/](http://code.google.com/p/django-plus/)
[See blog post](http://paltman.com/2008/04/11/keeping-contenttypes-and-permissions-updated-without-syncdb/)
You can put this script in the root of your project and run after deploying updates in your production environment.
This function is designed to make it easier to specify client-side query filtering options using JSON. Django has a great set of query operators as part of its database API. However, there's no way I know of to specify them in a way that's serializable, which means they can't be created on the client side or stored.
`build_query_filter_from_spec()` is a function that solves this problem by describing query filters using a vaguely LISP-like syntax. Query filters consist of lists with the filter operator name first, and arguments following. Complicated query filters can be composed by nesting descriptions. Read the doc string for more information.
To use this function in an AJAX application, construct a filter description in JavaScript on the client, serialize it to JSON, and send it over the wire using POST. On the server side, do something like:
> `from django.utils import simplejson`
> `filterString = request.POST.get('filter', '[]')`
> `filterSpec = simplejson.loads(filterString)`
> `q = build_query_filter_from_spec(filterSpec)`
> `result = Thing.objects.filter(q)`
You could also use this technique to serialize/marshall a query and store it in a database.
This is another example use of the [exception middleware](http://www.djangosnippets.org/snippets/638/). It shows how to log exceptions to a file. Someone wanted to do this to avoid DOS-ing the email server in case of a silly error.
(untested.)
I was tired browsing via tag to find snippets I saw a while ago. So I created a custom search engine with Google.
To try it out go to [http://henning.cco-ev.de/django/djangosnippets.html](http://henning.cco-ev.de/django/djangosnippets.html)
It's a template tag used to create boxes with nested divs (useful to keep the templates DRY). For example:
{% menubox titlevar %}
Content here
{% endmenubox %}
will generate the html with the nested divs
div class=box
div class=box-outer
div class=box-inner
Headline
Content
/div
/div
/div
[more detail on this blog post](http://pedro.valelima.com/blog/2007/sep/26/boxes-template-tags/)
The SplitTimeField and the corresponding widget SplitDateTimeWidget show two select boxes with one for hour from 0 to 23 and the other showing minutes 0,15,30 and 45 (can be customized very easily).
Usage:
-------
class TestForm(forms.Form):
start_time = SplitTimeField(widget=SplitTimeWidget)
end_time = SplitTimeField(widget=SplitTimeWidget)
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.