Friday, April 8, 2011

TurboGears 2 Editable Primary Key Field

TG2.1, nice web app framework. I just with it has better documentations. Compare to django, TG2.1 documentations are way behind. But, still it is much more flexible.

I encountered problem that TG2 Admin Page, created with TG Administration System, automatically set the (html) input field of the model's PK to disabled. Sprox assumes that your model's PK is auto-generated.

Some one already reported the issue here
and then created the proper tickets to sprox here

Got a good clue where to check, so after taking a look inside sprox.formbase source code, below is the reason why PK fields are non-editable.
class EditableForm(FormBase):
"..."
def _do_get_disabled_fields(self): fields = self.disable_fields[:]
fields.append(self.provider.get_primary_field(self.entity))
# automatically set PK field disabled return fields

same goes with: class AddRecordForm(FormBase)

I wrote it in here.

Hopefully useful for those who need it.

No comments:

Post a Comment