How to choose a subcategory to create a post

52 views
Skip to first unread message

Капылов Данил

unread,
Jul 3, 2014, 5:53:54 AM7/3/14
to web...@googlegroups.com
1) Post created in a particular category. - http://hostname/app/default/created_ad/<category>

2)The category tied subcategories.

How to make that SQLFORM display only radio button of equal sub categories. Not show subcategories not belong to this category.



def get_category():
    category_url_name = request.args(0)
    category = db.category(url_name=category_url_name)
    if not category:
        session.flash = 'page not fount'
        redirect(URL('index'))
    return category

def created_ad():
    category = get_category()
    db.ad_post.category.default = category.id
    form = SQLFORM(db.ad_post).process(next='view_post/[id]')
    return locals()


db.define_table('ad_post',
                Field('category', 'reference category'),
                Field('subcategory', 'reference subcategory', widget=SQLFORM.widgets.radio.widget,
                      requires=IS_IN_DB(db, db.subcategory.id, label='db.category.name')),
                Field('title', type='string', requires=IS_NOT_EMPTY()),
                Field('body', type='text', requires=IS_NOT_EMPTY()),
                auth.signature
)

Leonel Câmara

unread,
Jul 4, 2014, 7:11:34 AM7/4/14
to web...@googlegroups.com
You need to use ajax to change the options on the subcategory.

Here's an example I did for countries->state->city where the state options depend on the country and the city options on the state

Fabiano Almeida

unread,
Jul 4, 2014, 2:10:40 PM7/4/14
to web...@googlegroups.com

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages