Dear all,
I'm having problems trying to omit a MultipleSelectField in a
customised `tgext.admin.AdminContoller`.
I've got the following installed:
turbogears2-2.1
sprox-0.6.10
tgext.admin-0.3.10
tgext.crud-0.3.8
tw.forms-0.9.9
ToscaWidgets-0.9.10
I can't post the real model but the relevant part looks something like
this...
class A (DeclarativeBase) :
__tablename__ = 'a'
id = Column (
Integer,
autoincrement=True,
primary_key=True
)
bs = relation (
"B",
order_by="B.id",
primaryjoin="B.a_id == A.id",
backref="a",
)
class B (DeclarativeBase) :
__tablename__ = 'b'
id = Column (
Integer,
autoincrement=True,
primary_key=True
)
a_id = Column (
Integer,
ForeignKey (
'
a.id',
onupdate="CASCADE",
ondelete="CASCADE",
),
nullable=False,
)
The controller config for model `A` looks like this:
class A_Config (CrudRestControllerConfig) :
defaultCrudRestController = A_Controller
class edit_form_type (EditableForm) :
__model__ = A
__omit_fields__ = ['bs']
I created an `A` and 2 `B`s and assigned both `B`s to the `A`.
I then navigated to the edit form of the `A` and the `bs` field had
indeed been omitted. However after submitting the form I got the
following AttributeError: 'ModelController' object has no attribute
'replace'. I traced this back to an IntegrityError during the `put`:
(IntegrityError) b.a_id may not be NULL.
Is that correct behaviour? Should the b.a_ids be set to NULL if the
field is omitted? When I set B.a_id.nullable to True, the
IntegrityError was no longer generated but then I lost the assignment.
I then tried to solve this problem a different way by using
`__hide_fields__`.
class edit_form_type (EditableForm) :
__model__ = A
__hide_fields__ = ['bs']
However, after submitting the form I got a the same IntegrityError.
The input element generated by widget looked like this:
<input type="hidden" name="bs" class="hiddenfield" id="bs"
value="12">
I assume that value="12" comes from the two `
b.id`s (1 and 2). I did a
bit of research and found that more than one `input` element would be
necessary to correctly hide the 'bs' field in this case. Something
like this maybe?
<input type="hidden" name="bs[]" value="1" />
<input type="hidden" name="bs[]" value="2" />
When the 'bs' field is not hidden or omitted everything seems to work
fine.
All I really need is to prevent a user from editing this field. Any
help would be much appreciated,
jed