Thank you Benjamin.
Your explanation was clear and focused on what I want to do :)

Your example is equal to the code I produced due to the fact a self-referential schema doesn't work.

The answer to my question can be summarized as follow: it is not possible :)

Regards,
Stefano.



Il 01/08/11 12.55, Benjamin Sims ha scritto:
Hi Stefano,

I'm very much a beginner myself, but perhaps I can try and give you a pointer based on how I understand it and those with more experience can correct me if I get it wrong.

I'd say don't think of it as trying to convert your SQLAlchemy data model directly into a Colander schema by using your Category class directly. If you do want to do this, you may wish to look at FormAlchemy which is designed to attempt automatic form generation based on SQLAlchemy. What you are doing with a Colander schema is defining a schema for the form itself and the data it will be dealing with. So, although this will obviously be based on the data model, the two are not directly tied together. If I understand what you are trying to do correctly, code would be something like this:

----------------------------------------------------------------------------------------
class CategorySchema(colander.MappingSchema):
    name = colander.SchemaNode(
            colander.String()
        )
# You would probably draw this from a database query rather than hardcoding
    parents = (
        ('1', 'First Category'),
        ('2', 'Second Category'),
        ('3', 'Third Category')
    )
# This assumes that a category will only have a single parent - SelectWidget only allows for one selection
    parent_id = colander.SchemaNode(
        colander.Integer(),
        widget = deform.widget.SelectWidget(values = parents)
    )
    children = (
        ('4', 'Fourth Category'),
        ('5', 'Fifth Category'),
        ('6', 'Sixth Category'),
    )

    children_ids = colander.SchemaNode(
            deform.Set(),
widget = deform.widget.CheckboxChoiceWidget(values = children),
            title = 'Category'
        )

----------------------------------------------------------------------------------------

Once you have the data in and validated, you would then use it to build your SQLAlchemy relations as normal. Hope this makes sense.

Ben


On 31 July 2011 22:16, Stefano Fontanelli <[email protected] <mailto:[email protected]>> wrote:


    Hi folks,
    I'm a n00b in colander use, therefore forgive my simple question :)

    I'm trying to convert a SQLAlchemy schema in colander version.
    Is it possible to reproduce the schema written below, in pseudo code?

    class Category(colander.MappingSchema):

       name = colander.SchemaNode(colander.String())
       parent = Category()
       children = colander.SchemaNode(colander.Sequence, Category())


    Regards,
    Stefano.

-- You received this message because you are subscribed to the Google
    Groups "pylons-discuss" group.
    To post to this group, send email to
    [email protected]
    <mailto:[email protected]>.
    To unsubscribe from this group, send email to
    [email protected]
    <mailto:pylons-discuss%[email protected]>.
    For more options, visit this group at
    http://groups.google.com/group/pylons-discuss?hl=en.


--
You received this message because you are subscribed to the Google Groups "pylons-discuss" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en.


--
Ing. Stefano Fontanelli
Asidev S.r.l.
Via Osteria Bianca, 108/A 50053 Empoli (Firenze)
Tel. (+39) 333 36 53 294   Fax. (+39) 0571 1 979 978
E-mail: [email protected]   Web: www.asidev.com
Skype: stefanofontanelli

--
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en.

Reply via email to