0

模型.py

class Category(models.Model):
    ...

class Article(models.Model):
    category = models.ManyToManyField(Category, related_name='articles')
    ...

class Photography(models.Model):
    article = models.ForeignKey(Article, related_name='photos')
    image = models.ImageField(upload_to = 'photos')

表格.py

from foo.models import Category, Article, Photography
from django import forms

class EditArticleForm(forms.ModelForm):
    def __init__(self, *args, **kwargs):
        super(EditArticleForm, self).__init__(*args,**kwargs)

    class Meta:
        model = Article
        fields = ['category', 'second_field', 'another_one']
        widgets = {'category' : forms.ModelMultipleChoiceField(label=''),}

我需要的是用属于编辑表单中文章的第一张照片替换类别标签。当我删除widgets行时,表单按预期工作,但我一直试图先获取空标签,但出现此错误__init__() takes at least 2 arguments (2 given)谢谢。

4

0 回答 0