Yes, I am aware of that, but what file is that in? You didn't specify. Is that in the same controller the other snippet is in? If so, then you're redfining db and the table in your controller which in your second to last line of your post you say you're not doing.
I'm confused... I'd like to help, but need a clear picture of a minimal common.py, models.py and your controller that reproduces this error. -Jim On Thursday, February 27, 2020 at 10:05:28 AM UTC-6, Maurice Waka wrote: > > I already have that, see above code second last line on imports > > On Thursday, February 27, 2020 at 4:35:25 PM UTC+3, Jim S wrote: >> >> Where is db being defined in your controller? Are you importing it from >> common? >> >> In my controller I have >> >> from ..common import db, session, T, cache, auth, logger >> >> and later >> >> @action.uses("applications/index.html", session, db, T, auth.user) >> def index(): >> page['sub_title'] = A('MENU', _href=URL('index')) >> return dict(page=page) >> >> Does that help? If not, can you post a minimal common.py, models.py and >> your controller? >> >> -Jim >> >> On Thursday, February 27, 2020 at 5:55:23 AM UTC-6, Maurice Waka wrote: >>> >>> Hello, from this code, I have already defined my table in models as >>> follows: >>> >>> import os >>> import datetime as dt >>> from datetime import datetime, timedelta, date >>> from py4web import action, request, DAL, Field, Session, Cache, user_in >>> from py4web.utils.auth import Auth >>> from py4web import action, request, abort, redirect, URL, Field >>> from py4web.utils.form import Form, FormStyleBulma >>> from py4web.utils.publisher import Publisher, ALLOW_ALL_POLICY >>> from pydal.validators import * #IS_NOT_EMPTY, IS_INT_IN_RANGE, >>> IS_IN_SET, IS_IN_DB, IS_EMAIL, IS_MATCH >>> from pydal.validators import * >>> from . common import db, session, T, cache, authenticated, >>> unauthenticated, Field >>> from pydal.validators import * >>> >>> >>> ### Define your table below >>> >>> >>> # exposes services necessary to access the db.thing via ajax >>> publisher = Publisher(db, policy=ALLOW_ALL_POLICY) >>> # define session and cache objects >>> session = Session(secret="some secret") >>> cache = Cache(size=1000) >>> >>> >>> # define database and tables >>> #connection = sqlite.connect('cache.db', timeout=10) >>> db = DAL("sqlite://xstorage.db", folder=os.path.join(os.path.dirname( >>> __file__), "databases"))#db = DAL("sqlite://storage.db", >>> folder=os.path.join(os.path.dirname(__file__), "databases")) >>> #db = DAL( "postgres://mauricewaka:b3th32dau2a##@localhost:5432/py4db", >>> migrate=False) >>> auth = Auth(session, db) >>> # (configure here) >>> auth.enable() >>> >>> >>> db.define_table('answers', >>> Field('author', 'reference auth_user', default=auth. >>> user_id, writable=False, readable=False), >>> Field("message", 'text', requires=IS_NOT_EMPTY(), >>> notnull=False), >>> auth.signature >>> ) >>> >>> >>> >>> >>> In the controllers, this is my code: >>> >>> @authenticated() >>> @action.uses(auth.user) >>> def index(): >>> >>> ...some code... >>> yesterday = dt.datetime.utcnow() - dt.timedelta(days=1) >>> >>> db(db.answers.modified_on < yesterday).delete() >>> ...some more code.... >>> >>> >>> >>> But I get this errors: >>> Traceback (most recent call last): >>> File "/home/maurice/py4web/py4web/core.py", line 551, in wrapper >>> ret = func(*func_args, **func_kwargs) >>> File "/home/maurice/py4web/py4web/core.py", line 512, in wrapper >>> ret = func(*args, **kwargs) >>> File "/home/maurice/py4web/py4web/core.py", line 512, in wrapper >>> ret = func(*args, **kwargs) >>> File "apps/scaffoldx/controllers.py", line 571, in index >>> db(db.answers.modified_on < yesterday).delete() >>> File "/home/maurice/.local/lib/python3.6/site-packages/pydal/base.py", >>> line 763, in __getattr__ >>> return BasicStorage.__getattribute__(self, key) >>> AttributeError: 'DAL' object has no attribute 'answers' >>> >>> >>> >>> What could be wrong here and how can I solve it? >>> >>> N/B >>> >>> I have tried to define the table inside the controller code with an error >>> coming as : 'table already defined'. When I remove the definition then the >>> above error comes. >>> >>> Regards >>> >>> -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/web2py/e026128f-ef47-42b9-b0ed-fdcfa8599548%40googlegroups.com.