Unfortunately I still haven't gotten it to work.
Now getting an error saying: type 'exceptions.AttributeError'>
'NoneType' object has no attribute 'startswith'
[[Models]]
db.define_table(
'group_of_events',
Field('name', requires=[IS_NOT_EMPTY(), IS_NOT_IN_DB(db,
'group_of_events.name')]),
Field('description'),
Field('image', requires=IS_IMAGE()), # will expand this to a list
Field('date_created', requires=[IS_NOT_EMPTY(), IS_DATETIME()]), #
want timestamp actually
Field('tags'),
Field('website', requires=IS_HTTP_URL()),
Field('facebook', requires=IS_HTTP_URL()), # want to force user to
input a facebook.com URL
Field('owner', auth.user, IS_NOT_EMPTY()),
Field('events', 'list:reference event', requires=IS_IN_DB(db,
'event.id')), # How to do?: WHERE group_id=this->group.id
format='%(name)s'
)
db.define_table(
'event',
Field('name', requires=IS_NOT_EMPTY()),
Field('description'),
Field('image', requires=IS_IMAGE()), # might expand this to a list
Field('datetime', requires=[IS_NOT_EMPTY(), IS_DATETIME()]),
Field('location'),
Field('group_id', db.group_of_events, requires=[IS_NOT_EMPTY(),
IS_IN_DB(db, 'group_of_events.id')]),
format='%(name)s'
)
On Thu, Jun 21, 2012 at 4:31 AM, Anthony <[email protected]> wrote:
>> db.define_table(
>> 'event',
>> Field('name', requires=IS_NOT_EMPTY()),
>> Field('description'),
>> Field('image', requires=IS_IMAGE()), # might expand this to a list
>> Field('datetime', requires=[IS_NOT_EMPTY(), IS_DATETIME()]),
>> Field('location'),
>> Field('group_id', db.group, requires=IS_NOT_EMPTY()),
>
>
> db.group hasn't been defined yet, so you are getting a key error. Either
> define the event table after defining the group table, or use the
> alternative syntax for specifying a reference field:
>
And that's why I should never code at 4am! - /me made a very n00b db
design error.
Thanks for pointing it out.
> Field('group_id', 'reference group', ...)
>
>> Field('owner', [IS_NOT_EMPTY(), auth.user]),
>
>
> The second argument to Field() should be the type, but looks like you're
> passing a list of validators (and auth.user is not even a validator). You
> probably want something like:
>
> Field('owner', db.auth_user)
Yeah, I had it like that but did some last minute refactoring to
reduce the test-case and must've put it out of the brackets.
>
> Anthony
Thanks
On Thu, Jun 21, 2012 at 7:14 AM, villas <[email protected]> wrote:
> In addition to what Anthony has said, please save yourself a whole heap of
> future problems by avoiding SQL reserved words. Having a table name GROUP
> is going to bite you! Look at the 'reserved words' section of the book in
> the DAL chapter and do something like this to help you avoid future problems
> in this respect:
>
> db = DAL('sqlite://storage.db', check_reserved=['postgres', 'mssql'])
>
> Regards,David
Thanks for the advice... I'll change the name.
--