TextField? automatically fills itself when form is to be displayed. The data to fill the form is given by dictionary created from SQLObject class using function so_to_dict(). When we need to automatically select items within MultipleSelectField? according data from join, we need to patch function so_to_dict() to return dictionary containing also joins (not columns only).
Example:
MODEL:
class Genre(SQLObject):
titles = RelatedJoin('Title')
class Title(SQLObject):
genres = RelatedJoin('Genre')
FORM:
def get_all_genres():
return [(int(a.id), "%s" % a.name) for a in Genre.select()]
class TitleFields(WidgetsList):
genres = MultipleSelectField(name='genres',
options=get_all_genres, validator=Int())
class TitleForm(TableForm):
fields = TitleFields()
TEMPLATE:
${form.display(obj, action=action)}
HANDLER:
class TitleCont(BaseDataController):
form_widget = TitleForm()
@expose(template="plend.templates.form")
def edit(self, obj):
value = so_to_dict(obj)
return dict(form=self.form_widget, obj=value, action="save")