Fail to add entry to list:reference field

84 views
Skip to first unread message

Spring

unread,
Apr 7, 2013, 7:42:13 AM4/7/13
to web...@googlegroups.com
Hello there,

I'm using a list:reference type field (f_keypersons in the code below). Having two issues here:
1. When adding/editing a record the dropdown appears on the corresponding field with correct options, but NO "+/-" sign as usual list fields. 
2. After select one option value and submit the field is still blank when listing this record again. Checking the record in appadmin, the value under this field is [2L] while it is supposed to be [2] which is the id in the referenced table. Trying to manually assign a value to this field but can' change it.
Any help is appreciated.


Related code:
db.define_table('t_prospects',
   
Field('f_account', db.t_accounts, required=True,
          label
=T('Account')),
   
Field('f_project', db.t_projects, required=True,
          label
=T('Project')),
   
Field('f_keypersons', type='list:reference t_contacts', requires=IS_IN_DB(db, 't_contacts.id', '%(f_name)s'),
          label
=T('Key Person')),
    auth
.signature,
    format
='%(f_account)s',
    migrate
=settings.migrate)
db
.t_prospects.f_account.requries = [IS_NOT_EMPTY(), IS_IN_DB(db, 't_accounts.id', '%(f_name)s')]
db
.t_prospects.f_project.requries = [IS_NOT_EMPTY(), IS_IN_DB(db, 't_projects.id', '%(f_project)s')]

db.define_table('t_contacts',
   
Field('f_name', type='string', required=True,
          label
=T('Name')),
   
Field('f_tel1', type='string',
          label
=T('Telephone 1')),
   
Field('f_tel2', type='string',
          label
=T('Telephone 2')),    
   
Field('f_fax', type='string',
          label
=T('Fax')),
   
Field('f_mobile', type='string',
          label
=T('Mobile')),
   
Field('f_email1', type='string',
          label
=T('Email 1')),
   
Field('f_email2', type='string',
          label
=T('Email 2')),
   
Field('f_remarks', type='list:string',
          label
=T('Remarks')),
    auth
.signature,
    format
='%(f_name)s',
    migrate
=settings.migrate)
db
.t_contacts.f_name.requires=IS_NOT_EMPTY()


Anthony

unread,
Apr 7, 2013, 8:42:55 AM4/7/13
to web...@googlegroups.com
    Field('f_keypersons', type='list:reference t_contacts', requires=IS_IN_DB(db, 't_contacts.id', '%(f_name)s'),

For list:reference fields, it should be IS_IN_DB(..., multiple=True). Actually, you shouldn't need to set the "requires" attribute explicitly anyway because you will get IS_IN_DB(..., multiple=True) as the default validator for a list:reference field.

Anthony

冷春辉

unread,
Apr 7, 2013, 9:57:39 AM4/7/13
to web...@googlegroups.com
Hi Anthony,

I read in the book that "requires' will be set by default for "list:reference". I tried this, and the output is the same as with  IS_IN_DB(..., multiple=True), which is a multiple item box listing all options as shown in the pic below:
Inline image 1
And I still don't understand why the value of the field is '1L' instead of '1' as in t_contacts.id..

Regards,
Spring


--
 
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/zZ7LHTCcUUA/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

2.png

Massimo Di Pierro

unread,
Apr 7, 2013, 10:12:19 AM4/7/13
to web...@googlegroups.com
Reference fields are long integers.

>>> a = 1
>>> print a
1
>>> print repr(a)
1
>>> b = 1L
>>> print b
1
>>> print repr(b)
1L


For practical purpose they are the same but with long integers you do not run out of values. 

Anthony

unread,
Apr 7, 2013, 10:50:47 AM4/7/13
to web...@googlegroups.com

I read in the book that "requires' will be set by default for "list:reference". I tried this, and the output is the same as with  IS_IN_DB(..., multiple=True), which is a multiple item box listing all options as shown in the pic below:
Inline image 1

The above looks correct. What were you expecting?

Anthony

冷春辉

unread,
Apr 7, 2013, 12:36:28 PM4/7/13
to web...@googlegroups.com
The intention is to create a list of items each of which are selected from the dropdown of referenced table, similar to 'list:string' with a "+/-" sign at the end to add another item. When click the "+/-" sign it pops another dropdown list to add new item. I photoshoped the pic below to show what I want:

Inline image 2


By checking database records I realized that all "list" fields even in other tables cannot be modify by length any more. Below is a pic of db management in Appadmin. No "+/-" sign. Don't know what went wrong..
Inline image 1

Hope I explain clearly. Thanks for you time.





Anthony

--
4.png
3.png

Anthony

unread,
Apr 7, 2013, 1:09:21 PM4/7/13
to web...@googlegroups.com
The intention is to create a list of items each of which are selected from the dropdown of referenced table, similar to 'list:string' with a "+/-" sign at the end to add another item. When click the "+/-" sign it pops another dropdown list to add new item. I photoshoped the pic below to show what I want:

Inline image 2
If that's what you want, you'll have to create a custom widget -- web2py doesn't have a built-in widget that works like that. 
 

By checking database records I realized that all "list" fields even in other tables cannot be modify by length any more. Below is a pic of db management in Appadmin. No "+/-" sign. Don't know what went wrong..
Inline image 1

Hmm, can you confirm that jQuery is loaded on that page (the list widget requires jQuery)?

Anthony

冷春辉

unread,
Apr 7, 2013, 8:51:44 PM4/7/13
to web...@googlegroups.com
Hi Anthony,

I compared the layout.html against older version, the jQuery issue was resulted because I manually add:
<script src="{{=URL('static','js/web2py_bootstrap.js')}}"></script> (I thought jQuery was not included in Layout.html) Removing this line solved the problem. Also I will try to build a custom widget.
Thank a lot.

Spring



Anthony

--
Reply all
Reply to author
Forward
0 new messages