On Sep 6, 2011, at 2:38 PM, Mark Erbaugh wrote:

> Let's say there is a mapped (declaratively, but that shouldn't matter) class, 
> Data, that has fields Data.value1, ... Data.value10.
> 
> There is also an instance of this class, data that is populated from the data 
> table.
> 
> Obviously, you can get the values using data.value1, ...
> 
> But is there a simple way to get a data value using the instance object 
> (data) and a class field (Data.value1).
> 
> What's the easiest way given data and Data.value1 to get / set that value of 
> data.value1? 

Data.value1 is a Python descriptor, so Data.value1.__get__(data, Data) would do 
it.    Or getattr(data, Data.value1.key) as "key" is present on the SQLA 
instrumented attribute.


> 
> So far I've come up with:
> 
> Data.__getattribute__(data, Data.value1.property.columns[0].name)  but is 
> there a more direct way?
> 
> ==============
> 
> If you're curious, here's what I'm trying to do.  I have an calculation that 
> sums a calculation on all of a particular type of field. If I add a new field 
> of this type to the table, it would be nice if it were automatically included 
> in the calculation.
> 
> I've created a custom descendent of Column for this type of column. When the 
> constructor of this custom class is called during the table construction, it 
> adds the created field to a list. The calculation should then step through 
> the columns in this list when calculating the value.
> 
> 
> Thanks,
> Mark
> 
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To post to this group, send email to [email protected].
> 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.
> 

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected].
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.

Reply via email to