SqlAlchemy and PostgreSql datetime update
I have a PostgreSql table in which I want to update an attribute of type timestamp with timezone (I tried also without timestamp but it does not work). I'm using SqlAlchemy session for that purpose. I fetch an existing record, and update it with a current timestamp: from model import Table from dbconf import session t=session.query(Table).filter(Table.id==1).first() t.available=datetime.now() session.add(t) session.commit() After this command nothing change in the database. What am I doing wrong?
I can assume that you have model of this table, you should add there new update method like this: class table(Base): __tablename__ = 'table' id = Column(Integer, primary_key=True) available = Column(DateTime) asd = Column(Unicode(255)) def update(self, available=None, asd = None): #etc. if available: self.available = available if asd: self.asd = asd and updating happens then like this: import transaction with transaction.manager: t=session.query(Table).filter(Table.id==1).first() #search the object what you want to update t.update(available=datetime.now()) #you can update only one or several cell like this
Python - optimize matrix values using constraints, beginner
Read a list of subdirectories from command line arguement
Python Multiple Values For One Key in a defaultdict(dict)
Select rows in dataFrame with the same index using python
Python - Display key values before and after Findall(regex, output)
python AttributeError: 'str' object has no attribute '' for an object which is a panda data frame
Odoo 10 : Related field and inheritance from third parent
Nan when training model wit RMSE/ RMSLE loss function
How to override keras predict function?
good practices to extend a class with custom functions in python: when to apply and how to code it?
Sum of the integers from 1 to n
Create a list by multiplication but not have each list mirror
Make Django's ModelChoiceField display as a dropdown with title and image
Running Python Script at Startup to log mouse and keyboard activity in Linux
Create a list of dictionaries from a dictionary
What is difference between two redis configuration files named redis.conf and 6379.conf?