I would do it in this way:

Let's say there are two tables building and room_detail. Let building
be

> > db.define_table('building',
> >     Field('name','string'),
> >     Field('comment', 'string'))

Let room_details be:

db.define_table('room_detail',
Field('detail_key', string),
Field('detail_value', string),
Field('building', db.building))

For every new information for a room, you can use a new record with a
distinct detail_key like 'name', 'owner', etc. Further, every
detail_key can be a value from a lookup table like
'room_detail_lookup' which contains the superset of all possible
detail_key values:

db.define_table('room_detail_lookup', Field('lookup_name', string))

OR use a validator in the room_detail table:

db.room_detail.detail_key.requires = IS_IN_SET(['OWNER', 'NAME',...])

Hope this helps.

On Jul 19, 12:19 am, Jonathan Lundell <jlund...@pobox.com> wrote:
> On Jul 18, 2011, at 9:29 AM, Ismael Serratos wrote:
>
> > Hi!! How could I make custom fields for each record in a model, I mean:
>
> Seems like the answer depends on knowing more than we do about the apps 
> requirements.
>
> If you don't need direct SQL (eg search) access to the custom fields, you 
> could serialize an info dictionary into a blob in the room table.
>
> If you do need direct access, and all the info fields have the same type 
> (string, for example), then how about a roominfo table, with a key and a 
> value field, along with a room ID? Another buildinginfo table could contain 
> the info keys legal for each building.
>
>
>
>
>
>
>
>
>
> > I have:
>
> > db.define_table('building',
> >     Field('name','string'),
> >     Field('comment', 'string'))
>
> > db.define_table('room',
> >     Field('name','string'),
> >     Field('owner','string'),
> >     Field('building',db.building))
>
> > But every building need some extra info about each room, for example
>
> > Building1 needed info:
>
> > room.name room.owner room.building room.xinfo room.yinfo
>
> > Building 2 needed info:
>
> > room.name room.owner room.building room.ainfo room.binfo
>
> > etc, etc.
>
> > Basically following this structure:  
>
> > project                                   room                custom_attribs
> > -----                                     -------------             
> > --------------
> > attrib_assoc_id    -->         id                  <--  assoc_id
> > ...                                      

Reply via email to