i’m new to python and flask framework.
My problem is I have to make an edit page. So i need to pass all object’s exist infos into a form.
Detail:
My object have this kind of structure:
class TVChannel(Document):
__collection__ = 'tvchannels'
use_dot_notation = True
structure = {
'_id' : basestring,
'name' : unicode,
'streams' : {
'city1': {
'adapt' : basestring,
'hds' : basestring,
'hls' : basestring,
'rtmp' : basestring,
},
'city2': {
'adapt' : basestring,
'hds' : basestring,
'hls' : basestring,
'rtmp' : basestring,
}
}
}
and in the view:
channel_obj = db.TVChannel().get_id(channel_id) #load a channel's datas into an object from db
channel = ChannelForm(request.form, obj=channel_obj) #load channel form
return render_template('channel/new.html',form=channel, channel_id=channel_id)
The channel_object’s “name” they understand and pass it like normal. But the “streams”, they did not recognize and pass it to something like this:
class ChannelForm(Form):
_id = HiddenField()
name = TextField(_('channel name'))
streams = {
'city1': {
'adapt' : TextField(_('stream adapt link')),
'hds' : TextField(_('stream hds link')),
'hls' : TextField(_('stream hls link')),
'rtmp' : TextField(_('stream rtmp link')),
},
'city2': {
'adapt' : TextField(_('stream adapt link')),
'hds' : TextField(_('stream hds link')),
'hls' : TextField(_('stream hls link')),
'rtmp' : TextField(_('stream rtmp link')),
}
}
submit = SubmitField(_('Save'))
What should i do?
Or is there anyway to modify the way how object’s data passed into those parameter of the form?
Well found this in the documentation and i will use it for now:
in the view:
And in the form:
Now i’m working on when i “save” them.