Nevermind, I just figured it out. I had to define the dog table prior to 
the person table. Although I thought this wouldn't be a problem according 
to the web2py book.

However, the form now displays this weird disable input box along with the 
list of dog checkboxes:

<input class="hidden" disabled="disabled" name="dogs" type="text" />



On Thursday, February 7, 2013 3:20:19 PM UTC-5, [email protected] wrote:
>
> I am getting an error when using list:reference and the checkbox widget:
>
> db.define_table('person',
>     Field('name', requires=IS_NOT_EMPTY()),
>     Field('dogs', 'list:reference dog'))
> db.define_table('dog',
>     Field('name', requires=IS_NOT_EMPTY()))
>
>
> db.person.dogs.widget = SQLFORM.widgets.checkboxes.widget
>
> I have also tried to place the widget in the Field:
>
> Field('dogs', 'list:reference dog', 
> widget=SQLFORM.widgets.checkboxes.widget)
>
> But I get the same error:
>
> <type 'exceptions.SyntaxError'> widget cannot determine options of 
> person.dogs
> I am using (2012-10-21) stable version of web2py, if it helps.
>
> On Wednesday, February 6, 2013 4:26:26 PM UTC-5, Derek wrote:
>>
>> It's a list:reference field then, look at the reference in chapter 6: the 
>> database abstraction layer
>>
>> On Wednesday, February 6, 2013 2:09:50 PM UTC-7, [email protected] wrote:
>>>
>>> Hello, I was reading about the "Links to referencing 
>>> records<http://web2py.com/books/default/chapter/29/07>"  
>>> part in the online guide, but was confused how I would deal with custom 
>>> logic of inserting it to the database. The guide seems to already have the 
>>> values in the database to pull from. 
>>>
>>> If we take the person and dog database in the example, a person can own 
>>> many dogs, but a dog can only have one owner. 
>>>
>>> If we take the example one step further and say we're running an animal 
>>> shelter, we would have a list of people and a list of dogs, but we don't 
>>> have the connection between the two. If a person wants to adopt a dog, 
>>> they'll use a form which will have the following elements:
>>>
>>> Textfield for the person's name. 
>>> A list of checkboxes with the dog's name.
>>>
>>> Then upon successful form submission, the selected dogs are linked to a 
>>> person.
>>>
>>> I don't quite understand how the form is built using "form = 
>>> SQLFORM(db.person)" in this scenario. 
>>>
>>> Since SQLFORM builds its own html, how would web2py handle the dog 
>>> object? By default, it will probably use a textfield because the dog has a 
>>> String name, but what about the owner reference? Furthermore, the dog has 
>>> to be treated as a boolean since we are simply asking if this dog should 
>>> belong to the human listed on the form or not. I can't quite picture how 
>>> "SQLFORM.widgets.boolean.widget" 
>>> since a dog isn't a boolean value tied to a person. It's its own entity 
>>> with a name and an owner.
>>>
>>> The only way I can think of to solve this is to NOT use SQLFORM, but 
>>> rather SQLFORM.factory(). Then I would use "{{=form.custom.begin/end}}" to 
>>> manually format the form, create the Textfield for the person name, and 
>>> generate the checkboxes in a for loop given the list of dog names. When the 
>>> form passes basic validation with form.accepted, I would grab the person's 
>>> id and update the entry for all dogs that are returned checked. 
>>>
>>> Do I have the right idea or am I misunderstanding web2py design? Is 
>>> there an easier way to handle one-to-many relationships through a form?
>>>
>>>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to