I am somewhat new to Django and am trying to use the ModelFormSets alongside multiple-databases.
I'm trying to create an empty ModelFormSet that will allow me to create objects for a specific database and pull in the appropriate drop-downs from that database. What I'm seeing is that the Form Set has populated all of the drop-downs based on the Foreign Key values for the 'default' database and not the database of my choosing. Consider the following example where there are a different set of users on each databases ('default' and 'NotDefault'). The following code will always render a select list that contains the users from the 'default' database even though the QuerySet that I've passed into the ModelFormSet is using a different database. class ScheduledReport(models.Model): reportID = models.AutoField(db_column="reportID", primary_key=True) Owner = models.ForeignKey(user.User) class Meta: db_table = "scheduledReports" ReportFormSet = modelformset_factory(ScheduledReport) report_form = ReportFormSet(queryset=sr.ScheduledReport.objects.get_empty_query_set().using('NotDefault')) report_form.as_table() # Trigger the render After looking thorough the source code, I've realized that the ModelChoiceFields get populated using each form's instance's database: # django.forms.models qs = qs.using(form.instance._state.db) form.fields[self._pk_field.name] = ModelChoiceField(qs, initial=pk_value, required=False, widget=HiddenInput With that information I tried directly modifying the instances state without any success. (This worked in the case where I was using just a ModelForm and not a ModelFormSet) report_form = ReportFormSet(queryset=sr.ScheduledReport.objects.get_empty_query_set().using('NotDefault')) for f in report_form.forms: f.instance._state.db = 'NotDefault' report_form.as_table() # Trigger the rendering I'm all out of ideas and am lost in how I am supposed to use ModelFormSets in conjunction with Multiple Databases. Has anyone else run into this issue? Thanks Parker -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.