Hi guys,
Wanted to know whether it is possible to track changes made to the datatables and associate them with a user.
This can be a feature request )
Hi guys,
Wanted to know whether it is possible to track changes made to the datatables and associate them with a user.
This can be a feature request )
There’s not currently a built-in solution for this, but you could create a separate Logs
table and do app_tables.logs.add_row
whenever you want to track updates. You could use a transaction to ensure the log is accurate (see ref docs).
Here’s an app with a simple example of that:
https://anvil.works/build#clone:EE4PCBOSAQS5YXUJ=CB3CPSLYWYK4UPGDI7GQASQU
The names I’m entering are modifying a column in the Users
table, and being logged in the Log
table:
@anvil.server.callable
def change_name(name):
if anvil.users.get_user() is not None:
with anvil.tables.Transaction() as txn:
app_tables.log.add_row(
user=anvil.users.get_user(),
prev=anvil.users.get_user()['name'],
now=name,
when=datetime.now()
)
anvil.users.get_user()['name'] = name
The log table looks like this after I recorded that GIF:
(Moving this to Feature Requests.)