Login

Snippets by josho

Snippet List

Word-boundary-aware string truncation template filter

This is a custom template filter that allows you to truncate a string to a maximum of num characters, but respecting word boundaries. So, for example, if `string = "This is a test string."`, then `{{ string|truncatechars:12 }}` would give you "This is a..." instead of "This is a te".

  • template
  • filter
  • truncate
  • words
Read More

Making prepopulate_from work with ForeignKeys and other sorts of choice fields

This is a fairly small bit template that, if placed in your_project_dir/templates/admin/prepopulated_fields_js.html will override the template that is normally pulled by the preopulated fields templatetag in the admin. The result is that you can successfully specify a ForeignKey or other field involving choices as a source for prepopulate_from in your admin.py. It works just as well when there are multiple fields of both the text and choice variety.

  • javascript
  • admin
  • prepopulate
Read More

josho has posted 2 snippets.