The autocomplete cannot use format to represent a field but if you store
the representation in an computed field, you can use that for autocomplete.
On Saturday, 22 September 2012 22:23:51 UTC-5, alex wrote:
>
> Hi all,
>
>
>
> How to solve this:
>
>
>
> There are two tables, table "xref" has two fields with a reference to
> table "table". Look at the format of “table”.
>
>
>
> db.define_table('table',
>
> Field('name', type='string'),
>
> Field('number', type='integer'),
>
> auth.signature,
>
> *format*= lambda row: str(row.number) + ' (' +row.name + ')', ## @1
>
> migrate=settings.migrate)
>
>
>
> db.define_table('xref',
>
> Field('t1_ref', type='reference table',
>
> widget =
> SQLFORM.widgets.autocomplete(request, db.table.id, id_field=db.table.id)),
>
> Field('t2_ref', type='reference table',
>
> widget =
> SQLFORM.widgets.autocomplete(request, db.table.id, id_field=db.table.id)),
>
> auth.signature,
>
> migrate=settings.migrate)
>
>
>
> Now if in the controller I define
>
> form = crud.update(db.xref, record) to update one record
> in xref, or
>
> form = crud.create(db.xref) to create a new record in xref
>
>
>
> the autocomplete widget always returns the ids of the table "table", not
> the required format (see @1).
>
>
>
> The required format is shown correctly only with crud.read, or when in
> crud.update the property writabe of the field is set to False,
>
> for example as below:
>
>
>
> def edit():
>
> record = db.xref(request.args(0))
>
> form = crud.update(db.xref, record)
>
> db.xref.t1_ref.writable = False
>
> return dict(form=form)
>
>
>
> In this case the field t1_ref is represented correctly (as @1), the field
> t2_ref shows an autocomplete widget with only ids of table.
>
>
>
> How to make that the autcomplete widget shows always a list formatted as
> in @1, and not just the ids of the referenced table?
>
--