显示在django

时间:2015-06-23 03:55:12

标签: python django

我在django有一个模型表格。详情如下

forms.py

class QcResultForms(forms.ModelForm):
#:    series = forms.ModelChoiceField(queryset=Series.objects.all(),help_text='Series ID adjkalsdjl',empty_label=None)
#    workflow_process = forms.ModelChoiceField(queryset=WorkflowsProcess.objects.all(),help_text='Workflow Process',empty_label=None)

    class Meta:
        model = QcResult
        exclude = ('id','result','workflow_process','series',)

models.py

class QcResult(models.Model):
    id = models.AutoField(primary_key=True)
    workflows_process = models.ForeignKey('WorkflowsProcess', blank=True, null=True)
    series = models.ForeignKey('Series', blank=True, null=True)
    result = models.TextField(blank=True, null=True)  # This field type is a guess.

class Meta:
    managed = False
    db_table = 'qc_result'
    unique_together = (('workflows_process', 'series'),)

views.py

def add_qc_results(request):
    context_dict = {}
    if request.method == 'POST':
        form = QcResultForms(request.POST)
        if form.is_valid():
            f = form.save()
            return HttpResponseRedirect('/msrb/')
        else:
            print form.errors
    else:
        form = QcResultForms()
    context_dict['form'] = form
    template = get_template('msrb/add_qc_results.html')
    context = RequestContext(request,context_dict)
    return HttpResponse(template.render(context));

根据forms.py,它不应显示任何内容。但是,它仍会显示属于workflow_process的额外小部件,如下所示。

enter image description here

我不确定我在这里缺少什么

编辑:模板

{% extends 'msrb/base.html' %}
{% block body_block %}
    <h1> Add QC Result </h1>
        <form id="add_qc_result"  method="post" action="/msrb/add_qc_results/">
        {% csrf_token %}
        {% for field in form.visible_fields %}
            {{ field.help_text }}
            {{ field }}
            {{ field.errors  }}
            <br/>
        {% endfor %}
        <input type="submit" name="submit" value="Add QC Result" />
        </form>
{% endblock %}

EDIT2:

在打开检查器时,我找到以下代码:

<select id="id_workflows_process" name="workflows_process">

除了empty_label = True

之外,其与QcResultForms中的workflow_process相同

1 个答案:

答案 0 :(得分:0)

这里有一个错字:

exclude = ('id','result','workflow_process','series',)

制作本:

exclude = ('id','result','workflows_process','series',)