Re: [SQLObject] Saving a rol with a derivative atribute
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: Georgio B. <geo...@gm...> - 2013-09-11 14:46:13
|
Oleg, thank you for the clarification, once I have learned a bit about signals I will submit a patch to improve the documentation 2013/9/11 Oleg Broytman <ph...@ph...> > Hi! > > On Wed, Sep 11, 2013 at 10:25:31AM -0300, Georgio Barbosa < > geo...@gm...> wrote: > > I would like to know if it is possible to create a model class with a > > default attribute derived from another. > > > > An example: > > > > class Post(SQLObject): > > *title = StringCol()* > > content = StringCol() > > create_time = DateTimeCol(default=datetime.now) > > tags = RelatedJoin('Tag') > > author = ForeignKey('Author') > > *slug = StringCol(default=title.replace(" ", "-"))* > > It is possible but in a rather complex non-obvious way. You have to > use events (signals); unfortunately that gem of SQLObject is > underdocumented (to say mildly), so you need to consult the code. > See http://sqlobject.org/SQLObject.html#events-signals for the > starting point. Read events.py and lookup main.py to see how signals are > sent and how SQLObject uses returned values. > You need to catch RowCreateSignal and RowUpdateSignal -- they are > sent before INSERT and UPDATE correspondingly -- and update values to > your need in your signal handlers. > > It would be great if after you learn the details of events you sent a > patch to improve documentation. Or any other patch -- code, > documentation, tests -- any help will be greatly appreciated. > > Oleg. > -- > Oleg Broytman http://phdru.name/ ph...@ph... > Programmers don't die, they just GOSUB without RETURN. > > > ------------------------------------------------------------------------------ > How ServiceNow helps IT people transform IT departments: > 1. Consolidate legacy IT systems to a single system of record for IT > 2. Standardize and globalize service processes across IT > 3. Implement zero-touch automation to replace manual, redundant tasks > http://pubads.g.doubleclick.net/gampad/clk?id=51271111&iu=/4140/ostg.clktrk > _______________________________________________ > sqlobject-discuss mailing list > sql...@li... > https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss > |