Hi Ben, The database is normally routed via the model, rather than the form, so a ModelForm would generally just pick whatever the model uses. I would imagine that trying to hack on the form directly would be a Bad Plan(tm).
https://docs.djangoproject.com/en/1.10/topics/db/multi-db/#automatic-database-routing That has info on setting up simple read/write replicas, 'using' in raw queries, etc. too. Hope that helps, Anthony On 9 August 2016 at 10:38, Ben Finney <[email protected]> wrote: > Howdy all, > > How can I specify which database (by its alias name) a Django ModelForm > should use? > > (I'm having trouble getting the message onto the Django forum, so I'm > asking this Python-related question here too.) > > A Django ModelForm knows its corresponding model, and the fields > included. > > The ModelForm instance clearly knows how to specify a database, > internally. It can validate its fields against the database, and can > save a new model instance to the database. This implies its operations > have knowledge of which database to use. > > What I need is to access that as an external user, when creating the > instance. I can't find how to specify any database other than the > default, when creating the ModelForm nor when it interacts with the > database. > > What is the equivalent for using='foo' when instantiating a ModelForm > for the model, or calling its methods (ModelForm.clean, ModelForm.save, > etc.)? > > -- > \ “A free press is one where it's okay to state the conclusion | > `\ you're led to by the evidence.” —Bill Moyers | > _o__) | > Ben Finney > > _______________________________________________ > melbourne-pug mailing list > [email protected] > https://mail.python.org/mailman/listinfo/melbourne-pug >
_______________________________________________ melbourne-pug mailing list [email protected] https://mail.python.org/mailman/listinfo/melbourne-pug
