ModelForm中的Django TypeError

时间:2019-06-29 13:00:05

标签: python django modelform

我只是尝试呈现ModelForm,并且不断出现以下错误:

“ TypeError:EditManifestSelect.Meta.fields不能为字符串。您是要键入:('reference',)吗?”

我确实确实尝试按照上面的建议键入它,但是只是继续收到相同的错误。有任何想法吗?

FORMS.PY

class EditManifestSelect(forms.ModelForm):
    class Meta:
        model = Manifests
        fields = ('reference')

VIEWS.PY

def edit_manifest(request):
    if request.method == "POST":
        form = EditManifestSelect(request.POST)


        if form.is_valid():
            form.save()
            return redirect('display_orders')
    else:
        form = EditManifestSelect()
        return render(request, 'edit_manifest.html', {'form': form})

MODELS.PY

class Manifests(models.Model):

    reference = models.ForeignKey(Orders)
    cases = models.IntegerField()
    description = models.CharField(max_length=1000)
    count = models.IntegerField()

    def __str__(self):
        return self.cases

1 个答案:

答案 0 :(得分:1)

如下更改form.py的代码。

class EditManifestSelect(forms.ModelForm):
    class Meta:
        model = Manifests
        fields = ('reference', )