Write a custom csv importer. use the code in gluon as an example for parsing.
During the initial import, set the reference to None. While importing, keep a dictionary in memory that can hold all needed references to a record. After import, commit, and then go through your dictionary fixing all of the references to what they should be, according to the dictionary. This might require you to use something other than the record ID though, like something you can query to get the real id. This way if your csv is not fully 100% auto incremented you should be fine. -- Thadeus On Sat, Sep 25, 2010 at 6:41 PM, mdipierro <[email protected]> wrote: > There is no way to do this. When you import the first record, the > second does not exist yet therefore the reference cannot be adjusted > by web2py. This is why self references are never a good idea. Use a > link table instead. > > On Sep 25, 2:19 pm, Jurgis Pralgauskis <[email protected]> > wrote: >> Hello, >> >> I have Topics Tree like this >> >> db.define_table("Topics", >> Field("parent_id","reference Topics", label=T("Parent >> Topic"), >> #~ widget=my_hierarchical_options_widget, # probably >> overriden by requires >> requires=IS_EMPTY_OR(IS_IN_DB(db, >> 'Topics.id','Topics.name')) >> ), >> .... >> ) >> >> after exporting I get >> >> Topics.id,Topics.parent_id, ... >> 10,10,... >> 11,10,... >> >> but after reimporting the first record looses parent_id >> I can see by exporting again: >> 27,10,... >> 28,27,... >> >> I understand that it should have some hook to update its reference >> after it learns it's id. >> probably this is not very often way to model sth but is probably a bug >> - >> >> ps.: I was defining "root" topics this way, but I found workaround to >> define root's by parent_id=None ;) >

