Hello
I want to create a form with a SingleSelectField that will be dynamically
populated every time the form is called.
Here is my form
That works fine, but options are generated
only once, during Init (as far as i understand). and I want the options to change
every time the form is loaded.
I've tried a few things but they didn't work, and I don't understand how
prepare() works.
Thanks for the help!
--
You received this message because you are subscribed to the Google Groups "ToscaWidgets-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to toscawidgets-dis...@googlegroups.com.
To post to this group, send email to toscawidge...@googlegroups.com.
Visit this group at http://groups.google.com/group/toscawidgets-discuss.
For more options, visit https://groups.google.com/groups/opt_out.
Thanks,
I've tried that, after seeing tw2.sqla being recommended here somewhere...
My problem with that is that I didn't manage to get it to work
I don't understand this line, in the docs:
To set the query property to use ZopeTransactionExtension, appropriate code must be added to your model.
What exactly do I need to add to my model?
--
Thanks
Paul
I am using Turbogears 2.2 framework.
I uncommented that line:
DeclarativeBase.query = DBSession.query_property()
I am able can load data in to "DbSingleSelectField"
But i still need guidance.. Sorry for all the questions, I just don't get it
quite yet.
I added this line to my form
test = tws.DbSingleSelectField(entity=Building)
How do I decide which field to show? Currently I'm seeing the options as
objects:
a list of: <Building object at 0x0000000005B94550>
--
Thank you very much! I got it working, here are the important pieces of code, to summarize, and maybe help others
I'm using TurboGears2.2 and tw2.sqla, I wanted to create a form for creating new rooms objects, and associate it with a building (from a list of building from Database). Here is what I did:
On "model/__init__.py"
Uncomment this line (might be line 22)
DeclarativeBase.query = DBSession.query_property()
Here is my model:
I've added " __unicode__" method to return the field I want to view
in my template:
class Building(DeclarativeBase):
__tablename__ = 'buildings'
id = Column(Integer, autoincrement=True, primary_key=True)
name = Column(Unicode(255))
address =Column(Unicode(255))
def __unicode__(self):
return self.name
Here is my form:
import tw2.forms as twf
import tw2.sqla as tws
class RoomForm(twf.TableForm):
id = twf.HiddenField()
name = twf.TextField(validator=twc.Validator(required=True))
description = twf.TextArea()
building = tws.DbSingleSelectField(entity=Building, prompt_text=None,)
action = 'saveNewRoom'
buttons = [twf.SubmitButton()]
And here is my save method:
@validate(form=RoomForm,error_handler=room_form_error)
@expose()
def saveNewRoom(self,**kw):
room = Room()
room.name = kw['name']
room.description = kw['description']
room.building_id = kw['building'].id
DBSession.add(room)
redirect('/manage/buildings')
--
To unsubscribe from this group and stop receiving emails from it, send an email to toscawidgets-discuss+unsub...@googlegroups.com.
Thanks for the advices guys,
About tgext.crud, I tried that before but had to do a lot of work, to get the template to look good (I'm building in Hebrew – RTL). But thanks anyway, maybe I'll open a different post about that.
Anyway ToscaWidgets2 are great! (my 2nd turbogears project with them)
To unsubscribe from this group and stop receiving emails from it, send an email to toscawidgets-dis...@googlegroups.com.
I don't use TG2 just to help me get to the database though, so I think
the answer to your question depends on what other stuff you need.
--