Hello!
How do I make a database table where the fields are defined by another
table?
For example, suppose some users of my system are event organizers, and they
can define what fields would belong in a person's profile.
Then, attendees of that event have to fill out a profile with those specific
fields.
What is the best way to represent this information (the fields relevant for
an event's profile, and the event profiles of users) in a database?
What I have been thinking of so far is to define a table that holds the
definitions of profile fields:
db.define_table('event_profile_field',
Field('event', db.event),
Field('display_title','text'),
Field('data_type',
requires=IS_IN_SET('string','text','checkbox','list')),
Field('display_order', 'int'))
and then each user's profile is built up of multiple entries of the
following:
db.define_table('event_profile_entry',
Field('person', db.person),
Field('event', db.event),
Field('event_profile_field', db.event_profile_field),
Field('data') # XXX we need data to be of different types
However, as indicated above by the comment, I'm not sure if it is possible
to store different data types in the event_profile_entry.data field.
(I suppose I could just make it be 'text' type and have the code know that a
checkbox can only be True or False, for example).
Is there a more efficient/smarter way to do this?
Thanks,
Luis.