On Jul 19, 2008, at 5:54 AM, HellRaiser wrote:

>
> Hello
>
> I like to implement a custom Table object, which automatically add
> some custome rows to the Table the User create.
>
> #!/usr/bin/env python
> #-*- coding: utf-8 -*-
>
> from addressmanager.model import DBSession
> from sqlalchemy import Table, Column, Integer, ForeignKey, and_
>
>
> class MandateTable(Table):
>    def __init__(self, name, metadata, *args, **kwargs):
>        Table.__init__(self, name, metadata, *args,
>                       **kwargs)
>        self.append_column(Column("mandate_id", Integer,
> ForeignKey("mandates.mandate_id"), nullable=False))
>
>    def query(self, query, mandate):
>        return DBSession.query(self).filter(and_(query, "idmand=%i" %
> mandate.mandate_id))
>
> Something llike that.
> But now, when i start the application I got an error, that there is no
> Table object (ähh? but it inherit from Table).
>
> Is there a best practise to extend the table object? or to
> automatically add custom rows to a Table?


Table is not easy to subclass due to the metaclass which controls its  
creational pattern.   Since all you need here is a creational pattern,  
use a def instead:

def MandateTable(*args, **kwargs):
     args = args + (Column("mandate_id", Integer, ...),)
     return Table(*args, **kwargs)



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