python


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

Related Links

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?

Categories

HOME
jar
jsviews
blockchain
wildcard
visual-studio-2013
automated-tests
avl-tree
actionscript-2
goutte
octopus-deploy
pca
webmethods
cratedb
react-leaflet
scaling
opera-mini
mule-studio
zoomcharts
pyyaml
saiku
styles
koa
statusbar
python-textprocessing
frp
helper
thinking-sphinx
jboss5.x
pari
ipfw
polymorphism
css-counter
lego
forecasting
rhel.net
swagger-editor
equivalence
intellij-idea-2016
code-composer
google-account
context-free-language
onmouseover
range-v3
dimple.js
azureportal
component-pascal
forerunnerdb
butterknife
uicollectionviewlayout
selenium-firefoxdriver
adler32
polar-coordinates
festival
typhoon
ruby-2.0
gitweb
metalsmith
coordinate-transformation
squirrel
twgl.js
mfc-feature-pack
loopj
cctray
sonarqube5.3
getrusage
app.xaml
python-winshell
abas
twython
xjc
findcontrol
uptodate
adodb
google-earth-plugin
obfuscar
sysctl
microblaze
ogr2ogr
bullet
mfmailcomposeviewcontroll
alertifyjs
data-generation
jstack
circos
exiv2
fogbugz-api
driver-signing
sttwitter
ftp4j
ienumerator
shortcuts
socketstream
css-tables
getusermedia
mpmovieplayer
subtract
shim
supersized
point-sprites
jquery-selectbox
v4l
nssavepanel
cross-domain-policy
objectbrowser
scraperwiki
drawtext
trampolines
webrat
outlook-form

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App