I'm realy need to set a database to model form use to validate and save all data.. how can I pass this type of parameter? like .using(dbname) in view?
Without use db route, because I need all auth database and select to get in a specific database all other is set in my UserProfile database name, and I I try to use router but doesn't work. I have this view: def editaCliente(request, pessoa_id=None): if request.user.is_authenticated(): profile = request.user.get_profile() if pessoa_id: cliente = Cliente.objects.using(profile.dbname).get(idpessoa=pessoa_id) else: cliente = None if request.method == 'POST': formPessoa = ClienteForm(request.POST, instance=cliente, vUserProfile=profile) if formPessoa.is_valid(): cliente = formPessoa.save(commit=False) cliente.idrepresentante = profile.id_comerx3c # passando o id do representante cliente.internet = 'S' cliente = formPessoa.save() if cliente: return redirect('listaCliente') else: formPessoa = ClienteForm(instance=cliente, vUserProfile=profile) return render_to_response( 'cliente_novo.html', locals(), context_instance=RequestContext(request), ) but when call formPessoa.is_valid() show me these error: ('Error while preparing SQL statement:\n- SQLCODE: -204\n- Dynamic SQL Error\n- SQL error code = -204\n- Table unknown\n- PESSOA\n- At line 1, column 41', u'-204 -- SELECT FIRST 1 (1) AS "A" FROM "PESSOA" WHERE "PESSOA"."IDPESSOA" = -1') Thats because the form doesn't get the correct database, it`s take a default database, what I'm use only for auth profiles. Here is my modelform code: class ClienteForm(ModelForm): class Meta: model = Cliente def __init__(self, *args, **kwargs): vUserProfile = kwargs.pop('vUserProfile', None) super(ClienteForm, self).__init__(*args, **kwargs) self.fields["idcidade"].queryset = Cidade.objects.using(vUserProfile.dbname).all() self.fields["idpessoa"].widget.attrs['class'] = "input-mini" Thanks -- You received this message because you are subscribed to the Google Groups "Django users" group. To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/ESrhZn8sqIwJ. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.