<https://lh3.googleusercontent.com/-G1lUDU8N5ew/U_Ye1E9Un5I/AAAAAAAABRA/PeVR_Z4DC9g/s1600/Laptop.png>

<https://lh6.googleusercontent.com/-sWlQMM0cFak/U_YetUF23RI/AAAAAAAABQ4/07rrcetfsJs/s1600/Desktop.png>
I tried to create product table which has a category and productType,  when 
I want to add new product to the database I choose from the dropdown list 
in the category and the productType should be change depends on the 
selection from the category, but there is no action on dropdown sublist in 
productType field:

*here is my code:*

*in the model: db.py*
db.define_table("Product",
     Field("ProductID", "integer", notnull= True, default=None),
     Field("Category",  "list:string", notnull=True, default=None, 
requires=IS_IN_SET(['Desktop', 'Laptop','Component', 'Peripherals', 
'Networking', 'Software', 'Accessory'])),
     Field("ProductType", "list:string"),
     Field("Name", "string"),
     Field("Description",  "text"),
     Field("IteamCondition","string"),
     Field("Tags", "string"),
     Field("Price", "double", represent = lambda value, row: DIV('$ %.2f' % 
(0.0 if value == None else value), _style='text-align: right;')),
     Field("Image", "upload"))

Desktop = (['Home & Office', 'Gamer Desktop'])
Laptop = (['Notebook', 'Laptop'])
Component = (['CPU', 'Motherboard', 'Memory', 'Storage', 'Graphics Card', 
'Optical Drive', 'Power Supply', 'Case'])
Peripherals = (['Camera', 'Cooling', 'Headset', 'Keyboard', 'Mouse', 
'Monitor', 'Sound Card'])
Networking = (['Router', 'Switch', 'Wireless AP', 'NAS', 'Network Adapter', 
'Power Line Adapter'])
Software = (['Microsoft', 'Mac', 'Security'])
Accessory = (['Cable', 'Card Reader', 'Power'])

if (db.Product.Category == 'Desktop'):
    db.Product.ProductType.requires = IS_IN_SET(['Home & Office', 'Gamer 
Desktop'])
elif (db.Product.Category =='Laptop'):
    db.Product.ProductType.requires = IS_IN_SET(['Notebook', 'Laptop'])
elif (db.Product.Category == 'Component'):
    db.Product.ProductType.requires = IS_IN_SET(['CPU', 'Motherboard', 
'Memory', 'Storage', 'Graphics Card', 'Optical Drive', 'Power Supply', 
'Case'])
elif (db.Product.Category == 'Peripherals'):
    db.Product.ProductType.requires = IS_IN_SET(['Camera', 'Cooling', 
'Headset', 'Keyboard', 'Mouse', 'Monitor', 'Sound Card'])
elif (db.Product.Category == 'Networking'):
    db.Product.ProductType.requires = IS_IN_SET(['Router', 'Switch', 
'Wireless AP', 'NAS', 'Network Adapter', 'Power Line Adapter'])
elif (db.Product.Category == 'Software'):
    db.Product.ProductType.requires = IS_IN_SET(['Microsoft', 'Mac', 
'Security'])
elif(db.Product.Category == 'Accessory'):
    db.Product.ProductType.requires = IS_IN_SET(['Cable', 'Card Reader', 
'Power'])

*in controller: default.py*
def AddProduct():
    Product=db().select(db.Product.ALL)
    f=SQLFORM(db.Product, fields=['ProductID','Category', 'ProductType', 
'Name', 'Description','IteamCondition', 'Tags', 'Price', 'Image'])
    if f.accepts(request.vars, session):
        session.flash="Product added!"
    elif f.errors:
        Product = db(db.Product.Name==request.vars.Name).select()
        if len(Product)>0:
            
db(db.Product.ProductID==request.vars.ProductID).update(Category=request.vars.Category,
 
ProductType=request.vars.ProductType, Name=request.vars.Name, 
Description=request.vars.Description, 
IteamCondition=request.vars.IteamCondition, Tags=request.vars.Tags, 
Price=request.vars.Price, Image=request.vars.Image)
        else:
            session.flash="Error in input. Try again."
        redirect(URL(r=request, f='AddProduct'))
    return dict( form=f)

any help are appreciated.

-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to