Sorry, I had the parent declared as catelog_parent in the table. If you change it to parent it should work ;)
Also += is the same as append. On Wednesday, January 22, 2014 3:35:29 AM UTC+13, web2pygroup wrote: > > I attempted to copy/paste what you have so I can modify it for my needs. > However it immediately errors out with: > > AttributeError: 'Table' object has no attribute 'parent' > > So I thought I would comment out everything for the menu except > response.menu = [] and populate the database (have done this before and the > site comes up just no menu as expected). > > I then decided to try and populate the database fields. > > However when I try to populate it I immediately get an error > "IntegrityError: FOREIGN KEY constraint failed". What I did was, put > "Animals" for the title, for description I put "Main Animals Category", > then for the parent catelog I put "Animals" again. Upon seeing this I'm > confused as to how a subcategory would get identified. So I also tried > just putting "Animals" for the title, and filling in the description as > above, but leaving the parent catelog blank, it to also failed with exactly > the same error "IntegrityError: FOREIGN KEY constraint failed". So > effectively I'm unable to even put anything in the fields, an issue I never > had so I'm unsure what the problem is. > > Would it be possible to use the fields I have already established to > populate the menu? Since you have 3 fields identified in your table albeit > with slight differences, would it be possible to somehow incorporate that > into what I have? Could you also explain why you used "+=" instead of > append? Maybe I could figure out something from that. > > Thanks > > On Tuesday, January 21, 2014 12:11:59 AM UTC-6, James Burke wrote: >> >> Hi, >> >> I managed to get one working a little while ago doing this. This has been >> adapted for your situation, may require some tweaking: >> >> _tables.py - model >> db.define_table('store_catelog') >> >> >> db.define_table('store_catelog', >> Field('title', 'string'), >> Field('description', 'text'), >> Field('parent_catelog', 'reference store_catelog', default=None), >> format='%(title)s', >> redefine=True) >> >> menu.py - model >> response.menu = [] >> >> categories = db(db.store_catelog.parent == None).select(orderby=db. >> store_catelog.id) >> >> for category in categories: >> response.menu+=[ (T(category.title), True if active_page == str( >> category.title.lower()) else False, URL('default','page/%s' % (category. >> title.lower())), [ >> (T(i.title), True if active_page == str(i.id) else False, URL( >> 'default','page/%s' % (i.id)), []) for i in db((db.stored_category.parent >> == category.id)).select(db.store_category.ALL) if i.parent == category.id >> ]) ] >> >> The query returns any categories without a parent and adds them to the >> menu. While doing so looks for any subcategories using the category as a >> parent. >> >> Hope that helps you out. >> >> -James >> >> On Tuesday, January 21, 2014 9:33:50 AM UTC+13, americ...@gmail.comwrote: >>> >>> >>> Hi all, >>> >>> I have been trying for a little over 2 weeks to figure this out... >>> >>> I'm trying to generate a menu that drops down, I have been able to >>> statically create it by overwriting sample app that has the same drop down >>> menu like the web2py.com site. >>> >>> I have this in my db.py: >>> db.define_table('store_catalog', >>> Field('maincategory', 'string'), >>> Field('subcategory', 'string'), >>> Field('description', 'text')) >>> >>> >>> in my menu.py I have gotten this so far: >>> response.menu=[] >>> response.menu.append([T('Catalog'), False, '', >>> [(T('%s' % menucatchoice['maincategory']), False, 'link', >>> [(T('%s' % menucatchoice['subcategory']), False, >>> 'link'),]) for menucatchoice in rows ] ]) >>> >>> It gets me a drop down menu except that for each subcategory it repeats >>> adding it to the main category. Let's say there is only 1 main category and >>> 2 subs that go after that >>> Catalog (this just shows with the caret next to it as intended) >>> MainCategory >>> Sub >>> Sub >>> What I have does put the "Catalog" for the first but, what I get is: >>> MainCategory >>> (blank) >>> MainCategory(don't want this it's being repeated) >>> Subcategory >>> MainCategory(and this one is also a repeat) >>> Subcategory >>> >>> I have tried to break out the response.menu with so many different >>> .appends it's not funny. I have also tried adding the "[-1]". This was >>> the closest I have gotten to what I want it to look like. I'm at an >>> absolute loss on this, any and all help would be greatly 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/groups/opt_out.