From 19ed039ba6d65cecfd6e8ad6e47b5cb008350b04 Mon Sep 17 00:00:00 2001 From: Elrond Date: Sun, 25 Dec 2011 20:03:11 +0100 Subject: [PATCH] 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. --- mediagoblin/db/sql/models.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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" -- 2.25.1