Hi,

Thx for your answer!

This way I could get rid of the KeyError I mentioned (caused by the
db.self_referenced_table_name syntax) previously and everything seemed fine
but I'm not satisfied by the rendering of such a model.

My example:

db.define_table('div',
    Field('name', type='string'),
    Field('ul', type=db.ul),
    Field('child_div', 'reference div'),
    format='%(name)s')

I'm using SQLFORM.smartgrid to render the form/model. The behaviour I would
expect is that the child_div field would be rendered the same way as the
db.ul reference -> render some dropdown box with the names of all known
records to chose from.

But this doesn't happen for the child_div field. Here simply some input box
is rendered. I cannot make sense of that. I've tried to enter the id (or
name -> wrong, won't get saved) of a record that should be referenced but I
hope that there is better way.

Am I doing something wrong or is this the way it should work? If so maybe
someone could point me to some explaination why self references have to be
handled differently...


thx again

PS: I'm using the 1.99.2 release

2011/10/15 Anthony <abasta...@gmail.com>

> You can do self references -- see
> http://web2py.com/book/default/chapter/06#Self-Reference-and-Aliases.
>
> You would need to do Field('div', 'reference div').
>
>
> On Saturday, October 15, 2011 9:05:05 AM UTC-4, Erwin Pass wrote:
>>
>> Hi there,
>>
>> I saw on stackoverflow that you prefer questions here :)
>>
>> I need to display a form for a nested table structure. This means that
>> a record of a table might have a reference to another record of that
>> table. I have no idea how to model  something like this using DAL and
>> SQLFORM. I guess it isn't even possible but  you might have another
>> idea to implementi this.
>>
>> To illustrate my problem  think about some xml or html structure where
>> a node of a certain type can contain nodes of other types as well as
>> nodes of the same type.
>>
>> <div id='some_div_record'>
>>     <ul id='root_ul_ref'>
>>         <li id='first_li_ref'>text</li>
>>          ...
>>         <li id='nth_li_ref'>nth text</li>
>>      <ul>
>>      <div id='another_div_record'>
>>          ...
>>       </div>
>> </div>
>>
>> A div block might contain other div blocks. This seems not to be
>> possible to model using DAL:
>>
>> db.define_table('div',
>>     Field('text', type='string'),
>>     Field('ul', type=db.ul),
>>     Field('div', db.div))
>>
>> This attempt results in some KeyError: 'div', probably caused because
>> db.div is about to defined but referenced before it could be
>> constructed fully.
>>
>> The second part of the problem I'm facing might be an even tougher
>> one. Because I not only need to store references to _one_ another
>> record of the same table but to a unknown number of such records. (It
>> is not known how many divs the user choses to nest within...)
>>
>> I guess this requires another table like db.div_to_div which contains
>> the references (ids) but then I'm lost on ideas how to connect
>> implement the view which connects all this and enables the user to
>> enter his data.
>
>

Reply via email to