from django import forms
from ckeditor.widgets import CKEditorWidget
from dal import autocomplete
from .models import Tag,Category,Post
class PostAdminForm(forms.ModelForm):
    description = forms.CharField(widget=forms.Textarea, label = '摘要', required= False)
    content = forms.CharField(widget=CKEditorWidget(), label='正文',required=True)
    category = forms.ModelChoiceField(
        queryset= Category.objects.all(),
        widget=autocomplete.ModelSelect2(url='category-autocomplete'),
        label='分类',
    )
    tag = forms.ModelMultipleChoiceField(
        queryset=Tag.objects.all(),
        widget=autocomplete.ModelSelect2Multiple(url='tag-autocomplete'),
        label='标签'
    )
    class Meta:
        model = Post
        fields = ('category', 'tag', 'title', 'description', 'content', 'status')

