Instead of db.Word.dictionaryTypeID displaying (which is a foreign key in db.Word), I’d like a value from the foreign table to appear, i.e., DictionaryType. dictionaryName.
In the example below, when user cascades down to the Word table, it only shows db.Word.dictionaryTypeID but I’d like to add the corresponding DictionaryType. dictionaryName value to it.
def search_lang():
grid = SQLFORM.smartgrid(db.HumanLanguage, linked_tables=['Word','DictionaryType'], fields = [db.HumanLanguage.id, db.HumanLanguage.languageName, db.Word.id, db.Word.wordName, db.Word.definition, db.DictionaryType.dictionaryName,
db.Word.dictionaryTypeID],
user_signature=False)
return dict(grid=grid)
| id | Wordname | Definition | Dictionarytypeid | |
|---|---|---|---|---|
| 1 | beaker | glass jar | 1 |
Want to replace the "1" under Dictionarytypeid with value from foreign table.
Thanks,
Alex Glaros
--
---
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+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
There is a grandparent (HumanLanguage), parent (DictionaryType), child (Word), relationship. If I go straight from the grandparent to the child, "represent" works.
(First I click on HumanLangages, then I click on Word)If I go from the parent to the child, I get this message: <type 'exceptions.TypeError'> <lambda>() takes exactly 2 arguments (1 given)(First I click on HumanLangages, then I click on DictionaryType, then, I click on Word)If I reduce the number of parms to db.Word.dictionaryTypeID.represent = lambda id: db.DictionaryType(id).dictionaryName, then it works if I go from the parent to the child, but if I go from the grandparent to the child, I get <type 'exceptions.TypeError'> <lambda>() takes exactly 1 argument (2 given).If a join (result of a query) was allowed, it would solve the problem but I think they are not supported in smartgrid.
Any ideas would be much appreciated,Thanks,Alex
On Friday, February 22, 2013 5:24:48 AM UTC-8, Jim S wrote:
There is a grandparent (HumanLanguage), parent (DictionaryType), child (Word), relationship. If I go straight from the grandparent to the child, "represent" works.
(First I click on HumanLangages, then I click on Word)
If I go from the parent to the child, I get this message: <type 'exceptions.TypeError'> <lambda>() takes exactly 2 arguments (1 given)(First I click on HumanLangages, then I click on DictionaryType, then, I click on Word)If I reduce the number of parms to db.Word.dictionaryTypeID.represent = lambda id: db.DictionaryType(id).dictionaryName, then it works if I go from the parent to the child, but if I go from the grandparent to the child, I get <type 'exceptions.TypeError'> <lambda>() takes exactly 1 argument (2 given).
If a join was allowed, it would solve the problem but I think they are not supported in smartgrid.
Any ideas would be much appreciated,Thanks,Alex
On Friday, February 22, 2013 5:24:48 AM UTC-8, Jim S wrote:
Have you tried adding a format to your tables and defining your tables using objects instead of 'reference...'?I'm no web2py expert by any means, but I had a similar situation and when I changed the reference for my foreign id to db.other_table instead of 'reference other_table,' the format defined for that table was used instead of the id.Something like this:db.define_table('HumanLanguage',
Field('languageName','string'),
Field('forumLocations','string'),
Field('comments','string'),
format = '%(languageName)s'), # define a format
auth.signature)
db.HumanLanguage.languageName.requires = IS_NOT_EMPTY()
##
## Define DictionaryReferenceModel and WordReferenceModel above here
## DictionaryReferenceModel, WordReferenceModel should have a format
##
## Dictionary type means what category of dictionary is it? Medical, computer,etc. There is one for each language.
db.define_table('DictionaryType',
Field('dictionaryName','string'),
Field('comments','string'),
Field('languageID',db.HumanLanguage ), # changed to object
Field('DictionaryReferenceModelID', db.DictionaryReferenceModel), # changed to object
format = '%(dictionaryName)s', # define format
auth.signature)
db.DictionaryType.dictionaryName.requires = IS_NOT_EMPTY()
db.DictionaryType.languageID.requires = IS_IN_DB(db, 'HumanLanguage.id', '%(languageName)s',zero=T('choose one'))
db.DictionaryType.DictionaryReferenceModelID.requires = IS_IN_DB(db, 'DictionaryReferenceModel.id', '%(DictionaryTypeID)s',zero=T('choose one'))
db.define_table('Word',
Field('wordName','string'),
Field ('definition','string'),
Field('languageID', db.HumanLanguage ), # changed to object
Field('dictionaryTypeID',db.DictionaryType), # changed to object
Field('wordReferenceModelID',db.WordReferenceModel), # changed to object
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/va56WuVvbqI/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
web2py doesn't seem to accept that format on my windows version. I get<type 'exceptions.AttributeError'> 'DAL' object has no attribute 'DictionaryType'
The error below doesn't come up when there is no data:
<type 'exceptions.TypeError'> <lambda>() takes exactly 2 arguments (1 given)
The represent attribute works if there are two files in play instead of three
I created a simplified version and changed every field name in case there was some reserved word problem but it didn't work
What I will do is write something similar from scratch with different table and field names.
Thanks,
Alex
db.define_table('Word',Field('wordName','string'),Field ('definition', 'string'),
Field('languageID','reference HumanLanguage'),Field('dictionaryTypeID',db.DictionaryType),
Field('wordReferenceModelID','reference WordReferenceModel'),Field('comments','string'), auth.signature)
Can you show the line of code where this is happening?
Jim
Alex,I downloaded your app and ran it. If I understand you correctly, you're trying to get "Medical" to show up instead of "1" when you navigate to Humanlanguages -> English -> Dictionarytypes -> Words?I achieved this by editing your db.py to the following:##...
## Dictionary type means what category of dictionary is it? Medical, computer,etc. There is one for each language.
db.define_table('DictionaryType',
Field('dictionaryName','string'),
Field('comments','string'),
Field('languageID','reference HumanLanguage'),Field('DictionaryReferenceModelID', 'reference DictionaryReferenceModel'),
auth.signature,
format='%(dictionaryName)s') # added format tag here
db.DictionaryType.dictionaryName.requires = IS_NOT_EMPTY()db.DictionaryType.languageID.requires = IS_IN_DB(db, 'HumanLanguage.id', '%(languageName)s',zero=T('choose one'))
db.DictionaryType.DictionaryReferenceModelID.requires = IS_IN_DB(db, 'DictionaryReferenceModel.id', '%(DictionaryTypeID)s',zero=T('choose one'))
##...
..and I removed lines 16 and 17 from your default.py controller (the db.Word.dictionaryTypeID.represent statements).
Try that and see if that was what you were going for.
There is a grandparent (HumanLanguage), parent (DictionaryType), child (Word), relationship. If I go straight from the grandparent to the child, "represent" works.
(First I click on HumanLangages, then I click on Word)If I go from the parent to the child, I get this message: <type 'exceptions.TypeError'> <lambda>() takes exactly 2 arguments (1 given)(First I click on HumanLangages, then I click on DictionaryType, then, I click on Word)If I reduce the number of parms to db.Word.dictionaryTypeID.represent = lambda id: db.DictionaryType(id).dictionaryName, then it works if I go from the parent to the child, but if I go from the grandparent to the child, I get <type 'exceptions.TypeError'> <lambda>() takes exactly 1 argument (2 given).
If a join (result of a query) was allowed, it would solve the problem but I think they are not supported in smartgrid.
Any ideas would be much appreciated,Thanks,Alex
On Friday, February 22, 2013 5:24:48 AM UTC-8, Jim S wrote:
Those were the only changes that I remember. I've packed up the changes I made to your app and attached them, just in case there's something I don't remember changing. I've also attached a screenshot of where I see "Medical" to make sure we're on the same page about what you're trying to accomplish.As for where the functionality lies, I'm not exactly certain. I'm very new to web2py and I just happened to notice that using the format argument allowed id fields to be displayed according to another corresponding field in the database.Screen shot: http://dl.dropbox.com/u/169215/TechDictionarySS.PNG