from django import forms
from django.forms.utils import ErrorList
from django_summernote.widgets import SummernoteWidget

from .models import Post

EMPTY_TITLE_ERROR = "제목을 입력하세요"
EMPTY_CONTENT_ERROR = "내용을 입력하세요"


class DivErrorList(ErrorList):
    def __str__(self):
        return self.as_divs()

    def as_divs(self):
        if not self:
            return ''
        return '<div class="form-group has-error">%s</div>' % ''.join(['<div class="help-block">%s</div>' % e for e in self])


class PostForm(forms.ModelForm):
    class Meta:
        model = Post
        fields = ('title', 'content', 'file')
        widgets = {
            'title': forms.TextInput(attrs={'id': 'id_post_title', 'class': 'form-control', 'placeholder': 'Insert Title'}),
            'content': SummernoteWidget(),
        }
        error_messages = {
            'title': {'required': EMPTY_TITLE_ERROR},
            'content': {'required': EMPTY_CONTENT_ERROR}
        }

    def __init__(self, *args, **kwargs):
        kwargs_new = {'error_class': DivErrorList}
        kwargs_new.update(kwargs)
        super(PostForm, self).__init__(*args, **kwargs_new)

@@ -139,16 +139,28 @@
 ort Post
+, Attachment
 %0A%0AEMPTY_
@@ -1149,8 +1149,126 @@
 gs_new)%0A
+%0A%0Aclass AttachmentForm(forms.ModelForm):%0A    class Meta:%0A        model = Attachment%0A        fields = ('attachment', )%0A

Create AttachmentForm