Django对象没有在UpdateView中填充表单

时间:2014-07-22 13:24:05

标签: django templates object

出于某种原因,我在这个特定视图中的对象并未将其放入模板中的表单中。

在模板中,我可以{{ object }}获取预期结果,但表单为空。表格片段相当平淡。我还没有破坏任何样式。与视图相同。我有一个更大的检查权限等,但它们具有相同的最终结果:对象使其成为模板,但从不填充表单。

为了记录,我已经完成了form.first_name.value之类的内容,但我得到了None。有什么想法为什么UpdateView不会将对象内容插入到表单值?

~dit~按要求添加表格。


模板

#... snip
<form method="post" action="">
    {% csrf_token %}
    {{ form.as_ul }}
    <input type="submit" value="submit" />
</form>

查看

from forms import EmployeeCreateFormAutoIDPlusInvite
class EmployeeUpdateView(UpdateView):
    model = Employee
    template_name = 'employee_single.html'
    form_class = EmployeeCreateFormAutoIDPlusInvite

形式

class EmployeeCreateFormAutoID(forms.ModelForm):
    class Meta:
        model = Employee
        exclude = ['user','last_updated_date','last_updated_by','date_created',
            'created_by','reports_to','company','employee_id']

class EmployeeCreateFormAutoIDPlusInvite(EmployeeCreateFormAutoID):
    """
    Extends employee creation form by adding user info for invitations.
    """
    first_name = forms.CharField(label=_("First name"),
        max_length=30, required=True,
        help_text=_("Required. 30 character max length."))
    last_name = forms.CharField(label=_("Last name"),
        max_length=30, required=True,
        help_text=_("Required. 30 character max length."))
    email = forms.EmailField(label=_("Email"),
        help_text=_("Required for interactive employees, but if you are only adding"
            " this as a person for scheduling or invoicing, you needn't add it."))

0 个答案:

没有答案