Commits

Stephen McDonald  committed 29027f7

Correctly handle model field defaults in the quick blog post form.

  • Participants
  • Parent commits 0cce7bc

Comments (0)

Files changed (1)

File mezzanine/blog/forms.py

 from django import forms
 
 from mezzanine.blog.models import BlogPost
-from mezzanine.core.models import CONTENT_STATUS_DRAFT
+
+
+# These fields need to be in the form, hidden, with default values,
+# since it posts to the blog post admin, which includes these fields
+# and will use empty values instead of the model defaults, without
+# these specified.
+hidden_field_defaults = ("status", "gen_description", "allow_comments")
 
 
 class BlogPostForm(forms.ModelForm):
 
     class Meta:
         model = BlogPost
-        fields = ("title", "content", "status", "gen_description")
+        fields = ("title", "content") + hidden_field_defaults
 
     def __init__(self):
-        initial = {"status": CONTENT_STATUS_DRAFT, "gen_description": True}
+        initial = {}
+        for field in hidden_field_defaults:
+            initial[field] = BlogPost._meta.get_field(field).default
         super(BlogPostForm, self).__init__(initial=initial)
-        self.fields["status"].widget = forms.HiddenInput()
-        self.fields["gen_description"].widget = forms.HiddenInput()
+        for field in hidden_field_defaults:
+            self.fields[field].widget = forms.HiddenInput()