2009/3/29 Jason (spot) Brower <[email protected]>

>
> Gees, it was right in front of me.  Thanks!
> Regards,
> Jason
>
> On Sat, Mar 28, 2009 at 3:24 PM, Vidul Petrov <[email protected]>
> wrote:
> >
> > Hi Jason,
> >
> >    tags = db().select(db.tag.ALL,orderby=db.tag.name)
> >    users = db().select(db.users.ALL,orderby=db.users.nickname)
> >    tags = db.tag
> >    users = db.users
> >
> > should be:
> >
> >    tags = db().select(db.tag.ALL,orderby=db.tag.name)
> >    users = db().select(db.users.ALL,orderby=db.users.nickname)
> >
> >     tag_counter=db(db.tag.id>0).count()
> >     user_counter=db(db.user.id>0).count()
> >     # or just the length of the lists:
> >     tag_counter=len(tags)
> >     user_counter=len(users)
>

For a couple of reasons, I think you'd prefer to use len(tags)...  for one
thing db access count() in gnereal could give you a mismatch between
len(tags) and tab_counter....  for another, it's an unnecessary db  access.


> >
> >
> >
> >
> >
> > On Mar 28, 11:57 am, Jason Brower <[email protected]> wrote:
> >> It gives me an:
> >> AttributeError: 'str' object has no attribute 'nickname'
> >> on this line...
> >> response.write(person.nickname)
> >> but that all looks great...
> >> What the heck am I missing here...
> >> Second thing is the conditional I use in the view...  I have "if
> >> (users):", is that the best way to check if there is content in users
> >> model?  If not what would you recommend is the best way?
> >> Bester Regards,
> >> Jason
> >>
> >> ---------------------------------------------------
> >> Information:
> >> MODEL:
> >> db.define_table('users',
> >>         SQLField('first_name', 'string', length=15),
> >>         SQLField('last_name', 'string', length=15),
> >>         SQLField('nickname', 'string', length=15),
> >>         SQLField('phone_number', 'string', length=15),
> >>         SQLField('email', 'string'),
> >>         SQLField('password', 'password'),
> >>         SQLField('company', 'string', length=25),
> >>         SQLField('position', 'string'),
> >>         SQLField('street', 'string'),
> >>         SQLField('city', 'string', length=30),
> >>         SQLField('postal_code', 'string', length=15),
> >>         SQLField('country', 'string', length=30),
> >>         SQLField('created', 'datetime', default=now, writable=False),
> >>         SQLField('registration_key', length=128, writable=False,
> >> readable=False, default=''),
> >>         SQLField('avatar', 'upload'))
> >>
> >> CONTROLLER:
> >> #Manage Users
> >> def manage_users():
> >>     happenings = db().select(db.happening.ALL,orderby=db.happening.name
> )
> >>     tags = db().select(db.tag.ALL,orderby=db.tag.name)
> >>     users = db().select(db.users.ALL,orderby=db.users.nickname)
> >>     tags = db.tag
> >>     users = db.users
> >>     return dict(tags=tags, users=users, happenings=happenings,
> >> today=today)
> >>
> >> VIEW:
> >> {{extend 'layout.html'}}
> >> <h1>Users at your happening...</h1>
> >> <div id="edit_happenings">
> >>     <ul>
> >>     {{for happening in happenings:}}
> >>         <li>
> >>         {{=happening.name}}
> >>         </li>
> >>     {{pass}}
> >>     </ul>
> >> </div>
> >> <div id="edit_users">
> >>     {{if (users):}}
> >>     <ul>
> >>         {{for person in users:}}
> >>         <li>
> >>             {{=person.nickname}}
> >>         </li>
> >>         {{pass}}
> >>     </ul>
> >>     {{else:}}
> >>     <p>You have no users yet... click here to create one.</p>
> >>     {{pass}}
> >> <div id="edit_tags">
> >>     <ul>
> >>     {{for tag in tags:}}
> >>         <li>
> >>         {{=tag}}
> >>         </li>
> >>     {{pass}}
> >>     </ul>
> >> </div>
> >> </div>
> >>
> >> {{=BEAUTIFY(response._vars)}}
> > >
> >
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py Web Framework" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to