- changed status to resolved
open up "declarative base" for more flexible subclassing
Issue #1042
resolved
ctheune wants a total standalone function that does what the metaclass does, so thats one thing. The other thing is, this should be easy:
class MyBase(declarative_base()):
query = Session.query_property
def __repr__(self):
return <my custom repr whatever>
def some_other_method(self):
...
the above might not work since it wants to build a table/mapper for MyBase. I'm also not thrilled with little "hints" like __no_map__=True
and such since thats not really intuitive.
alternatively, you can just do it backwards with a mixin, but this is also not intuitive. We could just take the below and document it explicitly:
class _MyBase(object):
query = Session.query_property
def __repr__(self):
return <my custom repr whatever>
def some_other_method(self):
...
class MyBase(declarative_base(), _MyBase):
...
another idea:
class MyBase(object):
query = Session.query_property
def __repr__(self):
return <my custom repr whatever>
def some_other_method(self):
...
MyBase = declarative_base(cls=MyBase)
that might be the cleanest.
Comments (2)
-
reporter -
reporter - removed milestone
Removing milestone: 0.5.0 (automated comment)
- Log in to comment
ac934fc5330fad7ba971478d3d21fc5535fc848a