[web2py] Re: Display value from reference fields and not ids in SQLFORM.grid

2016-09-05 Thread Jacinto Parga
That's what I did in controller:

db.table2.field2.represent = lambda s,r: db(db.table1.id == 
s).select(db.table1.field2).first().field2



El viernes, 4 de septiembre de 2015, 22:57:27 (UTC+2), LoveWeb2py escribió:
>
> And of course I find it within a minute of posting... lol
>
> Here is my solution:
>
>
> in model:
> db.define_table('table2',
>  Field('field1','reference table1'),
>  Field('field2','reference table1', requires=IS_IN_DB(db, 
> db.table1.id, '%(field2)s')),
>  migrate=False)
>
> in controller:
> db.table2.field2.represent = lambda s,r: s.field2
> grid=SQLFORM.smartgrid(table2)
> return dict(grid=grid)
>
> Hope this helps someone in the future. Time for beer!
>
>
>
>
> On Friday, September 4, 2015 at 4:49:31 PM UTC-4, LoveWeb2py wrote:
>>
>> I've been struggling with this for hours! 
>>
>> db.define_table('table1',
>>   Field('field1', 'string'),
>>   Field('field2','date'),
>>   format='%(field1)s %(field2)s', migrate=False)
>>
>> db.define_table('table2',
>>  Field('field1','reference table1'),
>>  Field('field2','reference table1'),
>>  migrate=False)
>>
>> I'm trying to show table2 in a SQLFORM, but it only shows the field 1 
>> values, for both fields. I want to show field 2 values  in table 1 for 
>> table 2. In SQLFORM.grid it only returns the id instead of the grid.
>>
>> I'm so frustrated! 
>>
>> I've tried:
>> https://groups.google.com/forum/#!topic/web2py/bO1N4r2j0Dg
>>
>> http://stackoverflow.com/questions/1012179/how-to-generate-a-many-to-many-relationship-form-in-web2py
>> http://markmail.org/message/usmvxp5zctssog7d
>>
>  
>
>>
>> Any advice is greatly appreciated. I'm sure it's something simple, but I 
>> just can't seem to find it.
>>
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Display value from reference fields and not ids in SQLFORM.grid

2015-09-04 Thread LoveWeb2py
And of course I find it within a minute of posting... lol

Here is my solution:


in model:
db.define_table('table2',
 Field('field1','reference table1'),
 Field('field2','reference table1', requires=IS_IN_DB(db, 
db.table1.id, '%(field2)s')),
 migrate=False)

in controller:
db.table2.field2.represent = lambda s,r: s.field2
grid=SQLFORM.smartgrid(table2)
return dict(grid=grid)

Hope this helps someone in the future. Time for beer!




On Friday, September 4, 2015 at 4:49:31 PM UTC-4, LoveWeb2py wrote:
>
> I've been struggling with this for hours! 
>
> db.define_table('table1',
>   Field('field1', 'string'),
>   Field('field2','date'),
>   format='%(field1)s %(field2)s', migrate=False)
>
> db.define_table('table2',
>  Field('field1','reference table1'),
>  Field('field2','reference table1'),
>  migrate=False)
>
> I'm trying to show table2 in a SQLFORM, but it only shows the field 1 
> values, for both fields. I want to show field 2 values  in table 1 for 
> table 2. In SQLFORM.grid it only returns the id instead of the grid.
>
> I'm so frustrated! 
>
> I've tried:
> https://groups.google.com/forum/#!topic/web2py/bO1N4r2j0Dg
>
> http://stackoverflow.com/questions/1012179/how-to-generate-a-many-to-many-relationship-form-in-web2py
> http://markmail.org/message/usmvxp5zctssog7d
>
 

>
> Any advice is greatly appreciated. I'm sure it's something simple, but I 
> just can't seem to find it.
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.