0

我正在使用多个数据库

DATABASES = {
    'default': {
        # for local postgre databases
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': '2003',
        'USER' : 'postgres',
        'PASSWORD' : '3211',
        'HOST' : 'localhost',
    },
    'rana@rana.com': {
        # for local postgre databases
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'rana@rana.com',
        'USER' : 'postgres',
        'PASSWORD' : '3211',
        'HOST' : 'localhost',
    }
}

现在,在使用 inlineformset_factory 时,我正在尝试保存(using=rana@rana.com),但出现错误“save()在views.py中使用的地方出现了意外的关键字参数“使用”

def panelList (request, id=None):
    detail      = Panel.objects.using(username).filter(user=request.user).order_by('detail')
    buttonlable =   "Panel List"
    heading     =   "Panel List"
    formset     =   modelformset_factory(Panel, extra=1, max_num=1, can_delete=False,
                fields=('user','detail','panel_type','billing_address','contact','contact_person','status','email',),
                labels={'user':'','detail':'','panel_type':'','billing_address':'','contact':'','contact_person':'','status':'','email':'',}, 
                widgets={
                'user'    :   forms.HiddenInput(attrs={'placeholder':'user','class':'form-control col-sm mr-1 mt-1 border-muted bg-light border border-info','required':'true', 'value':user,}), 
                'detail'    :   forms.TextInput(attrs={'placeholder':'Name','class':'form-control col-sm mr-1 mt-1 border-muted bg-light border border-info','required':'true'}), 
                'panel_type'    :   forms.TextInput(attrs={'placeholder':'Type','class':'form-control col-sm mr-1 mt-1 border-muted bg-light border border-info','required':'true'}), 
                'billing_address'    :   forms.TextInput(attrs={'placeholder':'Address','class':'form-control col-sm mr-1 mt-1 border-muted bg-light border border-info','required':'true'}), 
                'contact'    :   forms.TextInput(attrs={'placeholder':'Contact','class':'form-control col-sm mr-1 mt-1 border-muted bg-light border border-info','required':'true'}), 
                'contact_person'    :   forms.TextInput(attrs={'placeholder':'Contact Person','class':'form-control col-sm mr-1 mt-1 border-muted bg-light border border-info','required':'true'}), 
                'email'    :   forms.TextInput(attrs={'placeholder':'email','class':'form-control col-sm mr-1 mt-1 border-muted bg-light border border-info','required':'true'}), 
                'status':   forms.HiddenInput(attrs={'placeholder':'status', 'class':'form-control col-sm mr-1 mt-1 bg-light border-muted'})})
    if request.method == "POST":
        formset = formset(request.POST)
        for form in formset:
            if form.is_valid:
                form.save(commit=False)
                form.user = request.user
                form.save(using=rana@rana.com)
        return redirect("panelList")
4

1 回答 1

0

您需要引用数据库名称,例如。form.save(使用='rana@rana.com')

于 2020-09-03T02:45:26.883 回答