Re: Saving a rol with a derivative atribute
Georgio Barbosa <[email protected]> Wed, 11 Sep 2013 11:46:05 -0300
| Newsgroups | gmane.comp.python.sqlobject |
|---|---|
| Message-ID | <CA+UBNT0c3=5DibS3fTJLHW6L6bJHsvk0cbhPxdcv404ScF_obA@mail.gmail.com> |
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 <[email protected]> > Hi! > > On Wed, Sep 11, 2013 at 10:25:31AM -0300, Georgio Barbosa < > [email protected]> 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/ [email protected] > 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 > [email protected] > https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss > ------------------------------------------------------------------------------ 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 [email protected] https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss