Login

Snippets by zakj

Snippet List

Clone model mixin

Add this as a superclass of any Django model to allow making copies of instances of that model: class Entry(models.Model, CloneableMixin): [...] e = Entry.objects.get(...) e_clone = e.clone() e_clone.title = 'Cloned Entry' e.save() The new object is saved during the clone process and ManyToMany relations are copied as well.

  • model
  • mixin
  • copy
  • clone
  • clonable
Read More

truncatehtml_at_word

Much stolen from base `truncate_html_words`. 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.

  • filter
  • html
Read More

JsonResponse

A subclass of `HttpResponse` useful as a shortcut in views; it chooses the correct JSON serializer based on whether or not it is passed a QuerySet.

  • ajax
  • serialize
  • json
Read More
Author: zakj
  • 24
  • 85

zakj has posted 3 snippets.