Skip to content

Commit

Permalink
Issue klen#37: Declare model field as MarkdownField and declare form …
Browse files Browse the repository at this point in the history
…field as MarkdownFormField
  • Loading branch information
Caroline Nadel committed Oct 25, 2014
1 parent d2d953c commit 0f1a76f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
8 changes: 8 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,19 @@ Setup
Use django_markdown
===================

#) Models: ::
from django_markdown.models import MarkdownField
class MyModel(models.Model):
content = MarkdownField()

#) Custom forms: ::

from django_markdown.fields import MarkdownFormField
from django_markdown.widgets import MarkdownWidget
class MyCustomForm(forms.Form):
content = forms.CharField(widget=MarkdownWidget())
content2 = MarkdownFormField()

#) Custom admins: ::

Expand Down
6 changes: 6 additions & 0 deletions django_markdown/fields.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django import forms
from .widgets import MarkdownWidget


class MarkdownFormField(forms.CharField):
widget = MarkdownWidget
9 changes: 9 additions & 0 deletions django_markdown/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from django.db import models
from .fields import MarkdownFormField


class MarkdownField(models.TextField):
def formfield(self, **kwargs):
defaults = {'form_class': MarkdownFormField}
defaults.update(kwargs)
return super(MarkdownField, self).formfield(**defaults)

0 comments on commit 0f1a76f

Please sign in to comment.