r/Python • u/yanni • Apr 27 '10
Beginners question about good design. Web2py.
I am putting together a site, from scratch, that is a cross between craigslist/yelp/travelocity. Basically there are multiple categories such as tutoring / computer repair / house related / etc.
When I am creating the model (database tables/etc) should I try to create a comprehensive submit form for all categories, or individual submit forms for each category? Some fields in one category have no meaning in another category. For example in tutoring there is an "Instructor-to-Student Ratio" field, and in computer repair there are Operating System type fields "apple, windows, linux etc."
Also some of the categories might have "sub-categories." Tutoring might have physical training, and educational, which in turn might have karate, ninjitsu, and math / science respectively.
What do the tables (in the model/DB) look like for this sort of a site?
1
1
u/ptemple Apr 27 '10
Use mptt. Integrates nicely into django. http://code.google.com/p/django-mptt/
Phillip.
2
u/mdipierro Apr 27 '10 edited Apr 27 '10
Here is preorder-tree-traversal in web2py:
http://www.mail-archive.com/[email protected]/msg06396.html
(it is kind of trivial so we did not considered it worthy of its own Google code project but perhaps we should do it). Anyway for the question posed by yanni the depth of tree is 2 (not arbitrary) and mptt is not the most efficient solution. Moreover he is not asking about models. He is asking about automatic generation of forms.
1
u/yanni Apr 27 '10
Interesting. It's a bit over my head for now, but the linked article (http://articles.sitepoint.com/print/hierarchical-data-database) provides a great introduction.
2
u/mdipierro Apr 27 '10
I am sorry you get voted down but reddit is nor very web2py friendly.
My two cents without knowing much about your project. I would create a table category, a table sub-category (that reference category) and I would generate the form dynamically (SQLFORM.factory) based on the list of subcategories.