简体   繁体   English

Django无法将值形式传递给构造函数

[英]Django cannot pass the value form to the constructor

I have tried everything, but I cannot pass the value form to the constructor of ContactCSVModel below: 我已经尝试了所有方法,但是无法将值形式传递给下面的ContactCSVModel的构造函数:

if request.method == 'POST':
    form = ConfiguratorForm(data=request.POST)

    # Try and import CSV
    ContactCSVModel.import_data(data=file, form=form)

the the class... 上课...

class ContactCSVModel(CsvModel, form):

    first_name = CharField()
    last_name = CharField()
    company = CharField()
    mobile = CharField()
    group = DjangoModelField(Group)
    contact_owner = DjangoModelField(User)

that CsvModel is part of Django-adaptors CsvModel是Django适配器的一部分

class ContactCSVModel(CsvModel, form): means that the ContactCSVModel extends a class called form . class ContactCSVModel(CsvModel, form):表示ContactCSVModel扩展了一个名为form的类。 I think this is what you really intended: 我认为这是您真正想要的:

class ContactCSVModel(CsvModel):
    # stüfe
    def __init__(self, form):
        # using the form for other stüfe.
        # maybe self.form = form?

I think what you are trying to do is use the form to pass data to the ContactCSVModel and ConfiguratorForm has the same fields? 我认为您正在尝试使用form将数据传递给ContactCSVModelConfiguratorForm具有相同的字段吗? If so, you should make the form into a ModelForm 如果是这样,则应将表单制作为ModelForm

class ConfiguratorForm(ModelForm):
    class Meta:
        model = ContactCSVModel

Otherwise, I am completely lost with what you are attempting to do... 否则,我完全迷失了您的尝试...

For example, what is currently in ConfiguratorForm and where did file come from? 例如, ConfiguratorForm当前file什么? file来自何处?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM