creating new objects with references to them

Steve Holden steve at holdenweb.com
Thu Nov 2 10:36:59 EST 2006


JohnJSal wrote:
> It seems like what I want to do is something that programmers deal with
> everyday, but I just can't think of a way to do it. Basically, I am
> writing a DB front-end and I want a new "Researcher" object to be
> created whenever the user presses the "New Record" button. He can open
> as many new records at a time as he wants and fill in the information.
> 
Seems straightforward.

> What I don't know how to do is handle this arbitrary number of objects.
> When it comes time to save the data to the DB, how do I access each
> object (to get the text fields associated with each)? Won't I have to
> have given each instance some name? Or is there some other way to do
> this? Simply creating a new instance each time the user presses "New
> Record" won't be good enough, because how do I retain a reference to
> that instance over the course of the program, even after a second or
> third instance has been created?
> 
Start with an empty list, and append new instances to it. Then when the 
user indicated completion you can iterate over the list INSERTing them 
into the database (presumably INSERTing the new researcher's details first).

To minimize consistency problems it would help to make all of these 
insertions as a single database transaction.

> Hope that makes sense. It seems like such a common task.
> 
regards
  Steve
-- 
Steve Holden       +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd          http://www.holdenweb.com
Skype: holdenweb       http://holdenweb.blogspot.com
Recent Ramblings     http://del.icio.us/steve.holden




More information about the Python-list mailing list