[Answered ]-MongoDB and dynamic html forms

1πŸ‘

βœ…

If you only need 3-4 sets of form widgets to display all necessary query forms for the 300+ categories, you should use Django forms to specify the widgets. You do not need 300+ Django forms for that as you can easily use multiple forms in one page.

As a quick example, your

<fieldset>
<legend>Price</legend>

<label for="price_from">from</label>
<input type="text" name="price_from">

<label for="price_to">to</label>
<input type="text" name="price_to">
</fieldset>

would become

class PriceForm(forms.Form):
    price_from = forms.IntegerField()
    price_to = forms.IntegerField()

…and of course the template to embed the form into which would provide the <fieldset> and other necessary html document structure.

EDIT:
As it seems that your form labels etc. depend on the category, you still need to have some information about the forms in the category documents in mongodb. However, by using django forms you get a lot of useful functionality for free, such as input validation.

You probably can parametrize the templates in such a way that you give the category-specific values (labels etc.) to the template from mongodb, along with the necessary forms.

πŸ‘€jhonkola

1πŸ‘

Technique for constructing dynamic filtered (faceted) search with Map/Reduce: http://ianwarshak.posterous.com/faceted-search-with-mongodb

I have successfully migrated the code to Python (and used it in a Django project).

πŸ‘€Dor

Leave a comment