Re: [web2py] Re: Record Versioning
No, I'm simply playing with SQLite. It's only for evaluation only. Anyway, I also noticed that it would store a new record regardless there is a modification in a field or not. Is it normal? Is there a way to avoid storing new record if in the end there is no difference when compared to previous record? Thanks, JF
[web2py] Re: Field vs id
It is not exactly identical, but changing the following line in my controller item.py, function edit: thispage = db.table[request.args(0)] with: thispage = db(db.table.fieldname==request.args(0)).select().first() provides me with the result I was waiting for for a URL like: http://127.0.0.1:8000/partcreation/item/edit/2122-123456789-00 Thank you very much! JF
[web2py] Field vs id
I think this information was actually somewhere in previous Books, but I just can't find it anymore in the 4th version. I would like to be able to get to a record, let's say from a function called edit. But using a Field from the table, not the id of the table. Example: This is accessed through the id of a record in a table. http://127.0.0.1:8000/partcreation/item/edit/1 But I would like to access it through a Field from the same table. Obviously this name/number must be unique. http://127.0.0.1:8000/partcreation/item/edit/2122-123456789-00 Note that the URL above is not working. I would like to know what would be the URL (and the code to put in the function) to use 2122-123456789-00 instead of 1. Thanks, JF
[web2py] Re: Record Versioning
Have another issue. It seems the datetime in my archive will always be the datetime of creation of the initial record, not the updates. Here is a glimpse of the Model: -- db.define_table('part', Field('iditm', db.item), Field('idbsn', db.business), Field('mpn', 'string'), Field('created_on', 'datetime', default=request.now, update=request.now, readable=False, writable=False), Field('created_by', db.auth_user, default=auth.user_id, readable=False, writable=False)) db.define_table('part_archive', Field('current_record', db.part), db.part) -- And here is a glimpse of the Controller: -- @auth.requires_login() def edit(): edit an existing mpn page thispage = db.part[request.args(0)] if not thispage: redirect(URL(r=request, f='index')) form = crud.update(db.part, thispage, onaccept=auth.archive, next = URL(r=request, f='edit', args=request.args), deletable = False) archive = db(db.part_archive.current_record==thispage.id).select() return dict(form=form, thispage=thispage, archive=archive) -- I thought the update=request.now in the Model would update the Field 'created_on'. What would be a good way to update this field whenever the Record is updated? I want to archive the datetime a table is updated. Thanks, JF
[web2py] Re: Record Versioning
Hi, I was working on 1.99.4, Cleaned the Application, Packed it to give it a try with 1.99.3. It actually worked correctly with 1.99.3. But it turns out that it is the Clean up that fixed the problem. Probably that the few modifications I made to the tables corrupted the database. Knowing that, I will always do a Clean up after modifying anything in the tables. Thanks, JF
[web2py] Re: Record Versioning
I don't know if having a field using the same name as the table was a problem, but I changed it anyway. It was confusing. But I finally figured out my problem was in the following lines (Note that I replaced the table name from mpn to part: db.part.iditm.requires = IS_IN_DB(db, 'item.ipn') db.part.idbsn.requires = IS_IN_DB(db, 'business.name') I just modified the code to be: db.part.iditm.requires = IS_IN_DB(db, 'item.id', '%(ipn)s') db.part.idbsn.requires = IS_IN_DB(db, 'business.id', '%(name)s') Now everything is working as expected. Thanks, JF
[web2py] Record Versioning
Hi, I'm trying the error versioning but I'm stuck with a curious error message and I don't see the link between what I did and this error. A part of my Model goes like this: db.define_table('item', Field('ipn', 'string'), Field('desc', 'string')) db.define_table('business', Field('name', 'string')) db.define_table('mpn', Field('iditm', db.item), Field('idbsn', db.business), Field('mpn', 'string')) db.define_table('mpn_archive', Field('current_record', db.mpn), db.mpn) A part of my Controller goes like this: form = crud.update(db.mpn, thispage, onaccept=auth.archive, next = URL(r=request, f='edit', args=request.args)) If I do remove the onaccept=auth.archive, everything works as expected, but if I keep it, I get the following error message: type 'exceptions.ValueError'(invalid literal for int() with base 10: '2134-123456789-00') This '2134-123456789-00' is from the field ipn in table item. But I don't see why it is not considered as a string correctly. Thanks, JF