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]> 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 
> pylons-discuss@googlegroups.**com<[email protected]>
> .
> To unsubscribe from this group, send email to pylons-discuss+unsubscribe@*
> *googlegroups.com <pylons-discuss%[email protected]>.
> For more options, visit this group at http://groups.google.com/**
> group/pylons-discuss?hl=en<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.

Reply via email to