Save using multiple databases

44 views Asked by At

I am using multiple databases

DATABASES = {
    'default': {
        # for local postgre databases
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': '2003',
        'USER' : 'postgres',
        'PASSWORD' : '3211',
        'HOST' : 'localhost',
    },
    '[email protected]': {
        # for local postgre databases
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': '[email protected]',
        'USER' : 'postgres',
        'PASSWORD' : '3211',
        'HOST' : 'localhost',
    }
}

now while using inlineformset_factory I am trying to save([email protected]) but getting error "save() got an unexpected keyword argument 'using" where I am using in 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([email protected])
        return redirect("panelList")
1

There are 1 answers

0
hoozecn On

You need to quote the db name, ex. form.save(using='[email protected]')