Implement _id proxy on sql objects (on User for now)
So that the old code can access the primary key still as "._id". Quite simple Python Descriptor thing. Very generic.
This commit is contained in:
parent
0575175846
commit
19ed039ba6
@ -11,6 +11,18 @@ from mediagoblin.db.sql.base import GMGTableBase
|
|||||||
Base = declarative_base(cls=GMGTableBase)
|
Base = declarative_base(cls=GMGTableBase)
|
||||||
|
|
||||||
|
|
||||||
|
class SimpleFieldAlias(object):
|
||||||
|
"""An alias for any field"""
|
||||||
|
def __init__(self, fieldname):
|
||||||
|
self.fieldname = fieldname
|
||||||
|
|
||||||
|
def __get__(self, instance, cls):
|
||||||
|
return getattr(instance, self.fieldname)
|
||||||
|
|
||||||
|
def __set__(self, instance, val):
|
||||||
|
setattr(instance, self.fieldname, val)
|
||||||
|
|
||||||
|
|
||||||
class User(Base):
|
class User(Base):
|
||||||
__tablename__ = "users"
|
__tablename__ = "users"
|
||||||
|
|
||||||
@ -32,6 +44,8 @@ class User(Base):
|
|||||||
## TODO
|
## TODO
|
||||||
# plugin data would be in a separate model
|
# plugin data would be in a separate model
|
||||||
|
|
||||||
|
_id = SimpleFieldAlias("id")
|
||||||
|
|
||||||
|
|
||||||
class MediaEntry(Base):
|
class MediaEntry(Base):
|
||||||
__tablename__ = "media_entries"
|
__tablename__ = "media_entries"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user