I'm fairly new to Python so am still learning about metaclasses.  I think I
pretty much understand how the uniqueobject recipe at
http://www.sqlalchemy.org/trac/wiki/UsageRecipes/UniqueObject works, and is
precisely what I'm looking for.  

Since I'd like to use this recipe with a number of tables/objects in my
database, I am trying to figure out how to make this recipe more generic.  

For example, let's say I have the following objects:

class user(object):
        __metaclass__ = EntitySingleton
        def __init__(self, firstname, lastname):
                pass

class pet(object):
        __metaclass__ = EntitySingleton
        def __init__(self, owner, species):
                pass

I changed __call__ method in EntitySingleton to accept an argument list so
it can  *args.  I tried changing it to **kwargs so I could pick up the names
of the variables (such as "firstname" and use that to filter the query with)
but that gave me an error.  Using
inspect.getargvalues(inspect.currentframe()) does not seem to be able to get
me the information I need either.  

I suppose I could change the initializers in user and pet classes to accept
**kwargs, which would allow me to change EntitySingleton's call method to
accept **kwargs as well.  However, I feel like this might not be the most
elegant solution nad was hoping someone could point me in the right
direction.

Thanks!
Orest


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to