djangosnippets.org: Latest snippets posted by zakjhttps://djangosnippets.org/users/zakj/2008-12-31T02:55:06.661285-06:00zakjClone model mixin
2008-12-31T02:55:06.661285-06:00zakjhttps://djangosnippets.org/snippets/1271/<p>Add this as a superclass of any Django model to allow making copies of instances of that model:</p>
<pre><code>class Entry(models.Model, CloneableMixin):
[...]
e = Entry.objects.get(...)
e_clone = e.clone()
e_clone.title = 'Cloned Entry'
e.save()
</code></pre>
<p>The new object is saved during the clone process and ManyToMany relations are copied as well.</p>
Freely redistributabletruncatehtml_at_word
2008-11-10T11:05:35.844109-06:00zakjhttps://djangosnippets.org/snippets/1176/<p>Much stolen from base <code>truncate_html_words</code>. The difference is that this filter takes a number of characters as its argument and truncates to the nearest word boundary less than that count, rather than specifying a number of words.</p>
Freely redistributableJsonResponse
2007-04-04T13:04:30.851926-05:00zakjhttps://djangosnippets.org/snippets/154/<p>A subclass of <code>HttpResponse</code> useful as a shortcut in views; it chooses the correct JSON serializer based on whether or not it is passed a QuerySet.</p>
Freely redistributable