Login

Markup Selection in Admin

Author:
jonathan
Posted:
August 15, 2007
Language:
Python
Version:
.96
Score:
3 (after 3 ratings)

This method lets you define your markup language and then processes your entries and puts the HTML output in another field on your database.

I came from a content management system that worked like this and to me it makes sense. Your system doesn't have to process your entry every time it has to display it. You would just call the "*_html" field in your template.

Requires: Django .96 Markdown Textile

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
MARKUP_LANG_CHOICES = (
    ('markdown', 'Markdown'),
    ('textile', 'Textile'),
    ('none', 'None'),
)

class Entry(models.Model):
    markup_lang = models.CharField('Markup Language', maxlength=255, choices=MARKUP_LANG_CHOICES, default='markdown')
    body = models.TextField(help_text='Use selected markup.')
    body_html = models.TextField('Body as HTML', blank=True, null=True)

    def save(self):
        if self.markup_lang == 'markdown':
	    import markdown
	    self.body_html = markdown.markdown(self.body)
	if self.markup_lang == 'textile':
	    import textile
	    self.body_html = textile.textile(self.body)
	if self.markup_lang == 'none':
	    self.body_html = self.body
	super(Entry, self).save()

More like this

  1. Browser-native date input field by kytta 1 month, 1 week ago
  2. Generate and render HTML Table by LLyaudet 1 month, 2 weeks ago
  3. My firs Snippets by GutemaG 1 month, 3 weeks ago
  4. FileField having auto upload_to path by junaidmgithub 2 months, 4 weeks ago
  5. LazyPrimaryKeyRelatedField by LLyaudet 3 months, 1 week ago

Comments

Please login first before commenting.