Created
October 1, 2011 19:45
-
-
Save jotbe/1256556 to your computer and use it in GitHub Desktop.
web2py: Write a record to an archive table without using forms and auth.archive
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Model: | |
# | |
#db.define_table('page', | |
# Field('name', unique=True), | |
# Field('title'), | |
# Field('body', 'text'), | |
# Field('created_on', 'datetime', default=request.now, update=request.now), | |
# Field('created_by', db.auth_user, default=auth.user_id), | |
# Field('change_note', length=200), | |
# format='%(title)s') | |
# | |
#db.define_table('page_archive', | |
# Field('current_record', db.page), | |
# Field('created_on', 'datetime', default=request.now), | |
# db.page) | |
# | |
>>> # Retrieve page | |
>>> this_page = db.page(db.page.name == 'main-page') | |
>>> # Set field current record to the current page | |
>>> db.page_archive.current_record.default = this_page | |
>>> old_page = this_page.as_dict() | |
>>> # Remove id. Alternative: del old_page['id'] | |
>>> old_page.pop('id') | |
14 | |
>>> db.page_archive.insert(**old_page) | |
19 | |
>>> db.page_archive(19) | |
<Row {'body': 'foobar blafasel narf blubb', 'name': 'main-page', 'current_record': 14, 'update_record': <function <lambda> at 0x102cacd70>, 'title': 'Main page', 'created_by': 1, 'created_on': datetime.datetime(2011, 10, 1, 17, 22, 21), 'change_note': 'Another change', 'id': 19, 'delete_record': <function <lambda> at 0x102cacde8>}> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment