Specify the database for a Django ModelForm instance
Ben Finney
ben+python at benfinney.id.au
Mon Aug 8 20:37:02 EDT 2016
Howdy all,
How can I specify which database (by its alias name) a Django ModelForm
should use?
(I've had trouble getting this question in to the Django forum, so I'm
trying here as this is still Python-related.)
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.)?
--
\ “The sun never sets on the British Empire. But it rises every |
`\ morning. The sky must get awfully crowded.” —Steven Wright |
_o__) |
Ben Finney
More information about the Python-list
mailing list