[sqlalchemy] Re: Updating existing objects

2008-12-27 Thread Eric Abrahamsen


On Dec 27, 2008, at 1:39 PM, Andreas Jung wrote:

 On 27.12.2008 3:06 Uhr, Eric Abrahamsen wrote:
 Sorry for the very beginner question, but I haven't been able to find
 a good discussion of this issue online (possibly because it's too
 basic).

 I'm using sqlalchemy as part of a basic web-based CRUD-style CMS.  
 I've
 got the Create, Read and Delete parts down, but I'm not sure how best
 to handle the Update part. Because the update page handler functions
 are generic and reused for many different models, all I can be sure  
 of
 is having a single object instance, and a dictionary of new values
 with which to update the instances attributes. All I can think of
 doing is

 instance.__dict__.update(value_dict)

 for k,v in value_dict.items().
setattr(instance, k, v)

Of course! Thanks a lot for your help.

Eric



 -aj

 
 begin:vcard
 fn:Andreas Jung
 n:Jung;Andreas
 org:ZOPYX Ltd.  Co. KG
 adr;quoted-printable:;;Charlottenstr. 37/1;T=C3=BCbingen;; 
 72070;Germany
 email;internet:i...@zopyx.com
 title:CEO
 tel;work:+49-7071-793376
 tel;fax:+49-7071-7936840
 tel;home:+49-7071-793257
 x-mozilla-html:FALSE
 url:www.zopyx.com
 version:2.1
 end:vcard



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Updating existing objects

2008-12-26 Thread Eric Abrahamsen

Sorry for the very beginner question, but I haven't been able to find
a good discussion of this issue online (possibly because it's too
basic).

I'm using sqlalchemy as part of a basic web-based CRUD-style CMS. I've
got the Create, Read and Delete parts down, but I'm not sure how best
to handle the Update part. Because the update page handler functions
are generic and reused for many different models, all I can be sure of
is having a single object instance, and a dictionary of new values
with which to update the instances attributes. All I can think of
doing is

instance.__dict__.update(value_dict)

Which I've heard is not the way to do it, and also seems to be leaving
out certain dictionary values in some cases. Is there an accepted way
to handle these kinds of operations?

Thanks,
Eric
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] filtering by datetime elements

2008-05-17 Thread Eric Abrahamsen

Hi there,

I'm new to this, so please be patient if I'm a little slow... I'm  
trying to filter Article objects by a datetime field ('pubdate'), and  
expected that I would be able to do something like this:

arts = sess.query(Article).filter(and_(Article.pubdate.year==year,  
Article.pubdate.month==month, Article.id==id)).one()

This gives me:
AttributeError: 'InstrumentedAttribute' object has no attribute 'year'

Apparently methods on attributes are reserved for sqlalchemy  
internals, and I'm not working with a straight Python object, as I'd  
thought. That makes sense, but can anyone suggest a simple substitute  
for what I'm trying to do here?

Thanks very much,
Eric

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: filtering by datetime elements

2008-05-17 Thread Eric Abrahamsen


On May 17, 2008, at 11:17 PM, [EMAIL PROTECTED] wrote:
 it's SQL that is not working with python objects, and the column
 pubdate (associated with type DateTime on python side) has no
 attr .year or .month.

 lookup the messages in the group, there were some sugestions long time
 ago, but AFAIremember one was something with strings, another with
 separate columns.

Thanks svil, this is good to know. I suppose there's no reason why I  
can't pull a simpler query into Python and then filter it by date  
there. It seems like doing this in the SQL query is going to be  
hackish no matter what, particularly when it's so simple to do in  
Python...

Thanks again,
Eric

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---