From: Elrond Date: Sun, 25 Dec 2011 19:03:11 +0000 (+0100) Subject: Implement _id proxy on sql objects (on User for now) X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=19ed039ba6d65cecfd6e8ad6e47b5cb008350b04;p=mediagoblin.git 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. --- diff --git a/mediagoblin/db/sql/models.py b/mediagoblin/db/sql/models.py index b87ff3aa..68b078a5 100644 --- a/mediagoblin/db/sql/models.py +++ b/mediagoblin/db/sql/models.py @@ -11,6 +11,18 @@ from mediagoblin.db.sql.base import 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): __tablename__ = "users" @@ -32,6 +44,8 @@ class User(Base): ## TODO # plugin data would be in a separate model + _id = SimpleFieldAlias("id") + class MediaEntry(Base): __tablename__ = "media_entries"