Code

Changes between Version 7 and Version 8 of UsingMarkup


Ignore:
Timestamp:
12/06/06 14:29:04 (7 years ago)
Author:
Sri
Comment:

updated

Legend:

Unmodified
Added
Removed
Modified
  • UsingMarkup

    v7 v8  
    1212    pub_date = models.DateTimeField('Date published', default=meta.LazyDate()) 
    1313    body_markdown = models.TextField('Entry body', help_text='Use Markdown syntax.') 
    14     body_html = models.TextField('Entry body as HTML', blank=True, null=True) 
     14    body = models.TextField('Entry body as HTML', blank=True, null=True) 
    1515 
    16     class META: 
    17         admin = meta.Admin( 
    18             fields = ( 
    19                 (None, {'fields': ('title', 'pub_date', 'body')}), 
     16    class Admin: 
     17        fields = ( 
     18            (None, {'fields': ('title', 'pub_date', 'body_markdown')}), 
    2019            ) 
    2120        ) 
     
    2322    def save(self): 
    2423        import markdown 
    25         self.body_html = markdown.markdown(self.body_markdown) 
     24        self.body = markdown.markdown(self.body_markdown) 
    2625        super(Entry, self).save() # Call the "real" save() method. 
    2726}}} 
    2827 
    29 Now you've got the same effect: when creating or editing entries in the admin, you'll only see the field which accepts Markdown syntax, but when saving, the body_markdown field will be auto-filled with the corresponding XHTML. Then in your template, you can pull in entry.body_markdown, and save yourself a little processing time. 
     28Now you've got the same effect: when creating or editing entries in the admin, you'll only see the field which accepts Markdown syntax(body_markdown), but when saving, the "body" field will be auto-filled with the corresponding XHTML. Then in your template, you can pull in entry.body, and save yourself a little processing time everytime the page is loaded.