How can I add added_by and updated_by field based on the session running in Piccolo Table? #300
Unanswered
sumitsharansatsangi
asked this question in
Q&A
Replies: 1 comment 6 replies
-
@sumitsharansatsangi You can do something like this to get the current session admin user from from piccolo_api.session_auth.tables import SessionsBase
def current_session_admin_user():
data = (
SessionsBase.select(SessionsBase.user_id)
.first()
.order_by(SessionsBase.user_id, ascending=False)
.run_sync()
)
return data["user_id"]
class Band(Table):
name = Varchar(unique=True)
added_by = ForeignKey(
auto_update=current_session_admin_user,
references=BaseUser,
)
updated_by = ForeignKey(
auto_update=current_session_admin_user,
references=BaseUser,
) Additionally, whenever a record is updated, the current admin user will be set to the |
Beta Was this translation helpful? Give feedback.
6 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I have a table as follows.
How can the
added_by
andupdated_by
field is to be filled according to the user updating the field?These are the fields which cannot be updated by the user (manually) updating the record, but to be filled based on the session running.
Beta Was this translation helpful? Give feedback.
All reactions