|
From: <sub...@co...> - 2005-12-21 18:46:52
|
Author: test
Date: 2005-12-21 18:46:46 +0000 (Wed, 21 Dec 2005)
New Revision: 1438
Modified:
FormEncode/trunk/formencode/sqlschema.py
Log:
Added an example of overriding to sqlschema docstring
Modified: FormEncode/trunk/formencode/sqlschema.py
===================================================================
--- FormEncode/trunk/formencode/sqlschema.py 2005-12-21 18:46:20 UTC (rev 1437)
+++ FormEncode/trunk/formencode/sqlschema.py 2005-12-21 18:46:46 UTC (rev 1438)
@@ -44,6 +44,29 @@
new_object = ps.to_python(form_input)
form_defaults = ps.from_python(aPerson)
edited_person = ps.to_python(edited_form_input)
+
+ To override the encoding and decoding, use ``update_object`` and
+ ``get_current``. In this example, lets say that we take a single
+ name field instead of a first_name and last_name (which is what
+ the database has)::
+
+ class PersonSchema(SQLSchema):
+ wrap = Person
+
+ def update_object(self, columns, extra, state):
+ name = extra.pop('name')
+ fname, lname = name.split(None, 1)
+ columns['first_name'] = fname
+ columns['last_name'] = lname
+ return super(PersonSchema).update_object(
+ columns, extra, state)
+
+ def get_current(self, obj, state):
+ value = super(PersonSchema).get_current(obj, state)
+ value['name'] = '%(first_name)s %(last_name)s' % value
+ del value['first_name']
+ del value['last_name']
+
"""
|