Re: [melbourne-pug] Specify the database for a Django ModelForm instance

2016-08-08 Thread Anthony Briggs
Database routers are for routing database queries. Forms and ModelForms are for validating user input. If you want to route an update to a specific database using a ModelForm, then you're going to have a bad time, ie. you'll need to write a lot of code for the specific API that you want, as opposed

Re: [melbourne-pug] Specify the database for a Django ModelForm instance

2016-08-08 Thread Ben Finney
Anthony Briggs writes: > On 9 August 2016 at 14:29, Ben Finney wrote: > > > I'm wanting to specify *exactly one* database at *run-time*, and > > have the operation use *that* database only (or fail if it can't). > > The configured multi-database routing is no use for that. > > You seem to be ver

Re: [melbourne-pug] Django: Best practice for importing data

2016-08-08 Thread Mike Dewhirst
Thanks Ben That confirms it for me. I'll go with migrations. Mike On 9/08/2016 2:50 PM, Ben Finney wrote: Mike Dewhirst writes: Can I ask why you are using manage.py to import csv data instead of a migration? There are different scenarios when each makes sense. * When the data import is

Re: [melbourne-pug] Specify the database for a Django ModelForm instance

2016-08-08 Thread Anthony Briggs
On 9 August 2016 at 14:29, Ben Finney wrote: > Anthony Briggs writes: > > > Or you can do it the Right Way(tm) and write a custom database router > > I appreciate the advice, but no, a database router is *not* right for > this. Specifying the database routing policy in a configuration file is >

[melbourne-pug] Django: Best practice for importing data (was: Specify the database for a Django ModelForm instance)

2016-08-08 Thread Ben Finney
Mike Dewhirst writes: > Can I ask why you are using manage.py to import csv data instead of a > migration? There are different scenarios when each makes sense. * When the data import is conceptually a defining feature of the database (e.g. a collection of status values), and should exist from

Re: [melbourne-pug] Specify the database for a Django ModelForm instance

2016-08-08 Thread Ben Finney
Anthony Briggs writes: > Right, so you can override the ModelForm's save() method, but you lose > all of the other nice Django things, like model init, checking, etc. > which you'll also have to recreate manually. Yes, exactly. All I need is to tell the ModelForm which database it should specify

Re: [melbourne-pug] Specify the database for a Django ModelForm instance

2016-08-08 Thread Mike Dewhirst
Ben Can I ask why you are using manage.py to import csv data instead of a migration? I ask because I'm just starting to think about an upcoming csv (xlsx actually) import task of my own. Thanks Mike On 9/08/2016 12:35 PM, Ben Finney wrote: The ModelForm validation functionality is bein

Re: [melbourne-pug] Specify the database for a Django ModelForm instance

2016-08-08 Thread Anthony Briggs
Right, so you can override the ModelForm's save() method, but you lose all of the other nice Django things, like model init, checking, etc. which you'll also have to recreate manually. Or you can do it the Right Way(tm) and write a custom database router as per the reply before that. Look for `Pri

Re: [melbourne-pug] Specify the database for a Django ModelForm instance

2016-08-08 Thread Ben Finney
Anthony Briggs writes: > I'm not sure what you're trying to do. Trying to write a management > command using model forms makes no sense - wouldn't you just load the > model instance directly in that case? The ModelForm validation functionality is being used, to validate input. Pseudocode::

Re: [melbourne-pug] Specify the database for a Django ModelForm instance

2016-08-08 Thread Anthony Briggs
Hi Ben, I'm not sure what you're trying to do. Trying to write a management command using model forms makes no sense - wouldn't you just load the model instance directly in that case? FWIW, there's only one instance of 'using' in Model forms, when saving over an existing instance: https://github.

Re: [melbourne-pug] Specify the database for a Django ModelForm instance

2016-08-08 Thread Ben Finney
Anthony Briggs writes: > The database is normally routed via the model, rather than the form, > so a ModelForm would generally just pick whatever the model uses. Okay, so how do I specify the arguments the ModelForm will use when interacting with the Model instance it creates? I'm trying to hoo

Re: [melbourne-pug] Specify the database for a Django ModelForm instance

2016-08-08 Thread Anthony Briggs
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-dat

[melbourne-pug] Specify the database for a Django ModelForm instance

2016-08-08 Thread Ben Finney
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 Mode

[melbourne-pug] train cancellations friday night

2016-08-08 Thread Jason King
Note that on the friday of the conference, it looks like metro is cancelling trains on several lines from 4:30 pm onwards. It doesn't look like its cancelling everything, but you might have to wait a while to get a ride home. www.metrotrains.com.au/planned-works/ ___