when u want it calculated? - just after load - just before save - if not set - always???
maybe use another attribute (_score) to store the value, map that one to table's column (either through mapper's property name or column's key), and let the score() either return _score if set or calc and store into _score (obj will become dirty!). or somehow attach on InstrumentedAttribute .__get__(), don't know if possible (easily). On Wednesday 18 April 2007 17:04:53 Julien Cigar wrote: > Hello, > > Simple question, I have a column "score" in a table which is > defined as a property in my model : > > @property > def score(self): > weights = dict(high=3, medium=2, likely=2, low=1, unlikely=1) > > score = weights.get(self.dispersion_potential, 0) > score += weights.get(self.natural_habitats, 0) > score += max((weights.get(x, 0) for x in self.impact_species)) > score += max((weights.get(x, 0) for x in > self.impact_ecosystems)) > > return score > > but it seems that SQLAlchemy can't see it, I have an error when I > .flush() : SQLError: (IntegrityError) null value in column "score" > violates not-null constraint > > I know that I could use a mapper extension for this (with > before_insert, before_update, etc) but could it not be possible to > do it with my @property ? > > Thanks, > Julien --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---