I understand your concern about the adding.
However, one of the fields of the child maps to product_id, so I need it 
available right away. Should I save it first then?

Freagell.

Paul McNett schreef:
> freek verstringe wrote:
>   
>> Hmm, actually I was trying to prefill with the last defined in database 
>> and then adding 1 to the id...
>>     
>
> Adding 1 to the id really needs to happen at the db layer, such as by using 
> an 
> auto_increment field, as some other person could be running your app, and 
> also adding 
> 1 to the last id, and then both you and that other person have assigned the 
> same id 
> to different records!
>
> For primary keys that are not auto-increment, you could use 
> dabo.lib.getRandomUUID(), 
> which is guaranteed to be unique every single time, but again you'd want to 
> do that 
> in the biz layer, not in the ui layer, using DefaultValues, like:
>
> def initProperties(self):
>    self.DefaultValues["id"] = dabo.lib.getRandomUUID
>
> For filling with info from the last record, that should happen in the biz 
> layer too. 
> Override afterNew(), and then:
>
> def afterNew(self):
>    # get a list of field names, not including the pk:
>    field_names = [f[0] for f in DataStructure where not f[2]]
>
>    # iterate the field names and fill in the value from the prior row:
>    for field_name in field_names:
>      self.setFieldVal(field_name, self.getFieldVal(field_name, 
> self.RowNumber-1))
>
> # note that the above will fail if this new record is the only row in the
> # dataset.
>
> Paul
>
>
[excessive quoting removed by server]

_______________________________________________
Post Messages to: Dabo-users@leafe.com
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-users
Searchable Archives: http://leafe.com/archives/search/dabo-users
This message: 
http://leafe.com/archives/byMID/blu143-w2215dea43b8064a347d71efe...@phx.gbl

Reply via email to