Found two ways of doing this:

1. use metaclass:

from sqlalchemy.ext.declarative import DeclarativeMeta

class PolymorphicSetter(DeclarativeMeta):
    def __new__(cls, name, bases, dictionary):
        if '__mapper_args__' in dictionary.keys():
            dictionary['__mapper_args__']['polymorphic_identity'] =
name
        else:
            dictionary['__mapper_args__'] = dict
(polymorphic_identity=name)
        return DeclarativeMeta.__new__(cls, name, bases, dictionary)

and in my base class Task:

class Task(DeclarativeBase):
    __metaclass__ = PolymorphicSetter

ii. Use class decorators.. write a function similar to the
polymorphicsetter class above and return the modified cls object..
then for every subclass of Task, use the decorator..

The advantage of the first approach is that, there is no need to do
anything once the Task class is extended..



On Sep 9, 7:51 pm, gizli <[email protected]> wrote:
> Thanks for the suggestion Wolodja but I dont think that would work.
> The self object is not defined at the time of class loading in python:
>
> >>> class Test:
>
> ...     qq = self.__class__.__name__
> ...     def fu(self):
> ...             print "fu"
> ...
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
>   File "<stdin>", line 2, in Test
> NameError: name 'self' is not defined
>
> I will post the solution here if I find any.
--~--~---------~--~----~------------~-------~--~----~
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