What I’m trying to do:
to show last three logged in User’s Name and time of clicking the button, in App Table , who clicks the “Approve” button when logged in
What I’ve tried and what’s not working:
I’m able to save the current user’name in the app table , but when a new user logs in it overwrites the old value in the table
Code
@anvil.server.callable
def approval_franchise(brcode,uname,data):
tday=datetime.datetime.today().strftime('%Y-%m-%d')
ttday=datetime.datetime.now()
a=f"http://some/link...................."
print(a)
print(uname,data)
f=data.update(approval_date_time=ttday,Approve_user=uname')
print(f)
kvanitha780:
data
… is passed in from the Client, so we don’t know exactly what it is. We can guess that it is an updatable data row, but we can’t tell which row.
My best guess is that you are reusing the same row each time , instead of creating a new record for each successful log-in.
Yes @p.colbert I’m using the same row each time, but I’m open to suggestions if you think there is any other easy way to do it.
Also there is a different app table for users (for name ,email, password etc)
How about creating a new row for each successful log-in?
If you keep rewriting the same row, all you’ll ever have is one row. But your Q&A title is asking for information from 3 different rows!
Yes from 3 different rows, how can we achieve that? I’m a noob and I’m totally blank
There’s a good example at the very start of
Using Data Tables from Python
I can also highly recommend the Tutorials and Examples links at the top of this page.
1 Like
what if i try to show last three rows of app table? how can i achieve that?
In Searching (querying) a Table , you’ll see that you can sort your results. So, assuming that you’ve recorded a timestamp of the log-ins (call this column last_login
), it would look something like
logins_in_reverse_order = app_tables.logins_by_timestamp.search(
tables.order_by("last_login", ascending=False)
)
Then you can just get the first 3 rows from logins_in_reverse_order
.
1 Like
Once you have this working, you’ll probably want to limit the growth of this table.
In my case, I run a Background Process to eliminate the old records. It runs once a night.
1 Like