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

py2app and xml.etree.ElementTree
What is the difference between isinstance('aaa', basestring) and isinstance('aaa', str)?
Is this essential functional programming feature missing from python?
Hooking into a wave-out on different platforms
What causes subprocess.call to output blank file when attempting db export with mysqldump?
How do I remove something form a list, plus string matching?
Reference to Part of List - Python
Django Delete all but last five of queryset
How do I limit the number of active threads in python?
Calculating the pixel size of a string with Python
Python nested lists and recursion problem
Problems PUTting binary data to Django
How to use long integers in Python to build a range?
Should I use Lex or a home-brewed solution to parse a formula?
Launching default application for given type of file, OS X
Python CGI script IOError Broken Pipe

Categories

HOME
ubuntu-16.04
computer-vision
zend-framework2
javamail
simpy
i2c
eval
currency
click
game-maker-studio-1.4
gatsby
dryioc
store
mousewheel
shippo
sql-update
ghost-inspector
cocoa-touch
profile
http-method
novnc
csh
metis
cortex-m3
mangodb
blackboard
pygooglechart
dhtmlx-scheduler
red-black-tree
polymorphism
pljson
powershell-remoting
swagger-editor
apiary
email-parsing
lumen-5.3
gist
pinvoke
bnd
decompress
volume
gce
quintus
static-code-analysis
unity3d-editor
visual-studio-templates
rmongodb
firepath
uiprogressview
boost-hana
achievements
remoteapp
asp.net-mvc-partialview
proxygen
asp.net-mvc-2
xmp
fortran90
approval-tests
datainputstream
enyo
document-oriented-db
wikitext
futuretask
windowlistener
harp
epl
virus
rhel5
iostream
getimagedata
yahoo-boss-api
adaptive-compression
ssms-addin
factors
opensocial
resource-files
facebook-chat
nsmatrix
image-zoom
installshield-2009
dynamic-binding
multiple-conditions
apache2.2
qss
pascals-triangle
gdataxml
usn
css-tables
n-layer
scrollto
gjs
selectonemenu
cross-domain-policy
hashalgorithm
path-manipulation
fileutils
ou
testunit
quick-search
winsnmp
divx

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