Now I understand.

Short answer. It cannot be done in the sense there is no API for it

Long answer. It can be done this way:

### define table post and set the format
### based on a field that does not exist
db.define_table('post',
    Field('title',length=256),
    Field('body','text',requires=IS_NOT_EMPTY()),
    Field('author',db.auth_user),
    format='%(title_short)s',
)

### define the field as a virtual field computed
class ComputedFieldsForPost:
    def title_short(self):
        return self.post.title[:40]+'...'
db.post.virtualfields.append(ComputedFieldsForPost())

### define the referencing table
db.define_table('comment',
    Field('post',db.post,writable=False,readable=False),
    Field('author',db.auth_user,writable=False,readable=False),
    Field('body','text',requires=IS_NOT_EMPTY()))

### modify an internal of the validator to
### fetch data required to compute the virtual field
db.comment.post.requires.fields=['post.id','post.title']

This kind of ugly but powerful.

On Jan 7, 12:25 pm, "KONTRA, Gergely" <pihent...@gmail.com> wrote:
> Sure.
>
> db.py:
>
> db.define_table('post',
>    Field('title',length=256),
>    Field('body','text',requires=IS_NOT_EMPTY()),
>    Field('author',db.auth_user),
>    )
>
> db.define_table('comment',
>    Field('post',db.post,writable=False,readable=False),
>    Field('author',db.auth_user,writable=False,readable=False),
>    Field('body','text',requires=IS_NOT_EMPTY()))
>
> In the example I provided, in the appadmin of comment, auth_user is
> displayed as a dropdown. I would like to do that for comment.post
> also.
>
> The format option make it possible to hack up some fields of the
> database, but it is not so flexible to display for eg. computed values
> of the post table.
>
> thanks in advance
> Gergo
> +-[ Gergely Kontra <pihent...@gmail.com> ]------------------+
> |                                                           |
> | Mobile:(+36 20)356 9656                                   |
> |                                                           |
> +- "Olyan lángész vagyok, hogy poroltóval kellene járnom!" -+
>
> On Thu, Jan 7, 2010 at 16:35, mdipierro <mdipie...@cs.depaul.edu> wrote:
> > Hi Gergo,
>
> > appadmin has nothing to do with t2 and t2 was deprecated long ago.
>
> > I guess you can still define db.post.represent but I am not sure what
> > do you want to do with it. What behavior do you expect? Can you
> > provide a concrete example?
>
> > On Jan 7, 9:31 am, "KONTRA, Gergely" <pihent...@gmail.com> wrote:
> >> Yes, AFAIK appadmin is a T2 thing.
>
> >> So, I wonder how can one rewrite the line below using
> >> db.post.represent (still that is more flexible)
>
> >> db.define_table('post',
> >>     Field('title',length=256),
> >>     Field('body','text',requires=IS_NOT_EMPTY()),
> >>     Field('author',db.auth_user),
> >>     format='%(title)s')
>
> >> db.post.represent = ?
>
> >> thanks
> >> Gergo
>
> > --
> > You received this message because you are subscribed to the Google Groups 
> > "web2py-users" group.
> > To post to this group, send email to web...@googlegroups.com.
> > To unsubscribe from this group, send email to 
> > web2py+unsubscr...@googlegroups.com.
> > For more options, visit this group 
> > athttp://groups.google.com/group/web2py?hl=en.
>
>
-- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to web...@googlegroups.com.
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en.


Reply via email to