Is there a way to add updated_at
column in piccolo ?
#277
Answered
by
dantownsend
sumitsharansatsangi
asked this question in
Q&A
-
How can I add a table as follows: class Pet(Table):
id=UUID(primary_key=True)
name=Varchar()
created_at =Timestamp(default=datetime.now())
updated_at =Timestamp(default=datetime.now()) # Not a right way What is happening here is that One way to do this is using Hooks , but if it has to be done in lots of table, Then it can be quite tedious work. class Pet(Table):
id=UUID(primary_key=True)
name=Varchar()
created_at =Timestamp(default=datetime.now())
updated_at =Timestamp(default_updated=datetime.now()) Other way it can be done is using custom datatype, but I don't feel comfortable with it because I have not understood it properly. |
Beta Was this translation helpful? Give feedback.
Answered by
dantownsend
Jan 21, 2023
Replies: 1 comment 2 replies
-
Give import datetime
class MyTable(Table):
updated_date = Timestamp(auto_update=datetime.datetime.now) |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
sumitsharansatsangi
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Give
auto_update
a try - it should do what you need: