Code

Changes between Version 2 and Version 3 of UsingMarkup


Ignore:
Timestamp:
12/03/05 03:35:42 (8 years ago)
Author:
ubernostrum
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • UsingMarkup

    v2 v3  
    11= CookBook - Using Markup Filters in Models = 
    22 
    3 The markup application (django.contrib.markup) is pretty handy for using filters like Textile or Markdown in your templates, but have a slight downside: every time a page is generated, you have to run the markup filter over the text, which may or may not be an acceptable performance hit. You could, if you wanted, just define a _pre_save hook which applies the filter to incoming text so it gets saved to your DB as HTML, but then you're in a pickle if you want to edit it again later. What to do, then? 
     3The markup application (django.contrib.markup) is pretty handy for using filters like Textile or Markdown in your templates, but has a slight downside: every time a page is generated, you have to run the markup filter over the text, which may or may not be an acceptable performance hit. You could, if you wanted, just define a _pre_save hook which applies the filter to incoming text so it gets saved to your DB as HTML, but then you're in a pickle if you want to edit it again later. What to do, then? 
    44 
    55One solution is found in the Textpattern CMS, which incorporates Textile. Textpattern accepts input in Textile syntax, and then saves two copies: one is the raw input, which is stored for later use when an item is being edited, and the other is the XHTML Textile produces for that input, which is used for actual page display. The idea here is that database columns are cheap, but processing time might not be. And this is easy to do in Django; for example, let's say you have a weblog where you'd like to use Markdown on the entries. You might define your Entry model like so: