Login

Snippets by jpt

Snippet List

MarkupField

This is a field that allows multiple markup types but also stores the pre-rendered result in the database which offers an advantage over calling one of the render methods each time. Example usage looks like: class BlogPost(models.Model): ... post = MarkupField() the various extra fields can then be accessed as follows: BlogPost.objects.get(pk=1).post # raw content BlogPost.objects.get(pk=1).post_markup_type # markup type (plain text, html, markdown, rest, textile) BlogPost.objects.get(pk=1).post_rendered # content of post rendered to html BlogPost.objects.get(pk=1).post_as_html # property that access post_rendered but marked safe for easy use in templates After writing my initial version of this I was pointed at the similar http://www.djangosnippets.org/snippets/1169/ I find mine a bit more useful as it includes ReST and includes a mark_safe call to allow showing the rendered HTML directly. I have however borrowed the nice idea of dynamically building MARKUP_TYPES from #1169. Also available via http://gist.github.com/67724.

  • fields
  • rest
  • markup
  • markdown
  • textile
  • restructuredtext
Read More
Author: jpt
  • 8
  • 16

very simplistic url cache flushing

This is an (overly simple) example of how to manually delete something from the cache. Usage is simply `delete_url_cache('/some_view/')` This most likely doesn't work when using Vary headers but does seem to work fine for the most general case of simply needing to programmatically flush the cache after certain actions.

  • cache
Read More
Author: jpt
  • 1
  • 3

jpt has posted 2 snippets.