Rapide développement avec FormAlchemy

Authors: Gael Pasgrimaud
Date: $Date: 2009-05-25$
Ce tutoriel présente FormAlchemy

Concept

Une table

>>> from sqlalchemy import *
>>> metadata = MetaData()
>>> users_table = Table('users', metadata,
...     Column('id', Integer, primary_key=True),
...     Column('name', String),
...     Column('fullname', String),
...     Column('password', String)
... )

Un mapper

>>> from sqlalchemy.orm import mapper
>>> class User(object): pass
>>> m = mapper(User, users_table)

Un formulaire

>>> from formalchemy import FieldSet
>>> html = FieldSet(User()).render()
>>> print html.strip() #doctest: +ELLIPSIS
<div>
  <label class="field_opt" for="User--name">Name</label>
  <input id="User--name" name="User--name" type="text" />
</div>
<script type="text/javascript">
//<![CDATA[
document.getElementById("User--name").focus();
//]]>
</script>
<div>
  <label class="field_opt" for="User--fullname">Fullname</label>
  <input id="User--fullname" name="User--fullname" type="text" />
</div>
...

Configuration

Extensions

En savoir plus

Remerciements

Questions ?