librelist archives

« back to archive

MongoAlchemy + WTForms

MongoAlchemy + WTForms

From:
Pronoy Chopra
Date:
2012-05-02 @ 06:30
Hello,

I was reading up on MongoDB and it seems inherent to MongoDB to have a 
dynamic forms to enter data. If the Forms' model is set then it really 
doesn't exploit the real use of Mongo then does it?

I could really use a small example to generate a dynamic form and input 
the data into MongoDB or any other way. I know to create a dynamic form 
a subclass has to be made and go on from there, but if anyone could 
provide a very small example, as in how to use them in the views etc. I 
would be very grateful

Thanks
Pronoy Chopra

Re: [flask] MongoAlchemy + WTForms

From:
Jesaja Everling
Date:
2012-05-02 @ 07:07
Hello,

if you define your form-fields up front you don't really exploit the
possibilities of MongoDB, that's true. But you could still use WTForms
to generate dynamic forms, and just save all your data to a Mongo
document. You could also dynamically construct the forms yourself in
HTML, of course.

Maybe these two links help, it's two articles on how to generate
dynamic form fields in Django:
http://jacobian.org/writing/dynamic-form-generation/
http://www.b-list.org/weblog/2008/nov/09/dynamic-forms/

The first link uses the __init__ method to add dynamic fields, the
second one a factory function. I don't know if that's what you are
looking for, but it should be possible to adapt that to WTForms.
I don't have dynamic forms, but here is an example for how I use
WTForms with a MongoDB model (I use MongoAlchemy), maybe that's useful
to you:
http://www.dpaste.org/h4I2g/

Best Regards,

Jesaja Everling


On Wed, May 2, 2012 at 9:30 AM, Pronoy Chopra <pronoyc@gmail.com> wrote:
> Hello,
>
> I was reading up on MongoDB and it seems inherent to MongoDB to have a
> dynamic forms to enter data. If the Forms' model is set then it really
> doesn't exploit the real use of Mongo then does it?
>
> I could really use a small example to generate a dynamic form and input
> the data into MongoDB or any other way. I know to create a dynamic form
> a subclass has to be made and go on from there, but if anyone could
> provide a very small example, as in how to use them in the views etc. I
> would be very grateful
>
> Thanks
> Pronoy Chopra

Re: [flask] MongoAlchemy + WTForms

From:
pronoyc@gmail.com
Date:
2012-05-02 @ 11:18
Hello,


> You could also dynamically construct the forms yourself in
> HTML, of course.


Yes, but manual validation and other features get left out. It's better to
use WTForms.


> Maybe these two links help, it's two articles on how to generate
> dynamic form fields in Django:
> http://jacobian.org/writing/dynamic-form-generation/
> http://www.b-list.org/weblog/2008/nov/09/dynamic-forms/

The first link uses the __init__ method to add dynamic fields, the
> second one a factory function. I don't know if that's what you are
> looking for, but it should be possible to adapt that to WTForms.
>

Even the second one uses __init__ method overriding. But I was wondering if
there is more Flask related example rather than a Django one. It's
obviously better than having nothing at all :) but I am still hoping for
more. Either way thanks for this.


> I don't have dynamic forms, but here is an example for how I use
> WTForms with a MongoDB model (I use MongoAlchemy), maybe that's useful
> to you:
> http://www.dpaste.org/h4I2g/


This helps, in getting started of course, but yes I think I have to use
dynamic forms. I was thinking of having a document for the form fields and
another to hold the data. So every custom page has custom fields and custom
data entries.
Except I don't know how to begin coding this :(
Anyone with any other ideas?

Pronoy

Re: [flask] MongoAlchemy + WTForms

From:
pronoyc@gmail.com
Date:
2012-05-02 @ 11:52
>
> http://www.b-list.org/weblog/2008/nov/09/dynamic-forms/


This link doesn't really tell you how to create dynamic forms. It just
shows you how to include or exclude a previously made field according to a
pre set condition. What I am looking for is, the user presses a button and
a new field is generated and he can enter the data and that gets saved in
the db.document

Pronoy