Wednesday, August 4, 2010

Re: Saving formsets with multiple databases

Sorry if this is obvious and you're looking for a more direct way, but If it's only the formset save that fails, I would suggest:

instances = formset.save(commit=False)
for instance in instances:
    instance.save(using=database)

I have never used multiple databases though, so I don't know if that works or if there is a better method.

- Paulo

On Tue, Aug 3, 2010 at 11:05 PM, Melanie <melanieilambert@gmail.com> wrote:
I am developing a formset for an application which uses multiple
databases.  On load of the formset, I am able to utilize:

model.objects.using(database).get(id)

to get an instance of the object from the active database.  However,
when the formset is submitted, I generate a new formset from the data
in request.POST:

formset = SampleFormSet(request.POST)

When attempting to save the formset to the database, I attempted to
pass the "using" parameter in the save method:

formset.save(using=database)

and got the error:

save() got an unexpected keyword argument 'using'

which suggests to me that the save method on the formset does not
support multiple databases.  Is there any known way to save a formset
when using multiple databases?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment