Hello,
I'm trying to extend mapped object functionalities in sqlalchemy 0.3.

I'd like to change the way the properties mapped to object work, in order to support additional __getitem__, __setitem__, __delitem__ methods, in order to pass info to the GUI in a cleaner way.

Take this example:


tests = Table("test", metadata,
          Column("id", Integer, Sequence("prove_id_seq"), primary_key=True, nullable=False),
          Column("text", String(30)),
          Column("number", Integer),
          )

class Test(object):
    pass

testmapper = mapper(Test, tests)

Let's suppose the Test object is my main model, so I want to add some business logic to it, and I also want to let some additional info 'slip through' to the GUI. E.g., I would like to set keys like 'hidden', 'readonly', or attach a validator on the columns, without employing a is_hidden() or is_readonly() or get_validator() method on the Test class: I'd just like to do something like that:

>>>t = Test()
>>>print t.id["hidden"]
True
>>>t.text["readonly"] = True

Those additional info wouldn't make their way into the db of course, and their values would be set by the model on a per-class basis.

In order to do this, I've coded a pretty simple 'extproperty' object which uses __get__, __set__ and __delete__ to return values when the property is called, but defines additional __getitem__ and __setitem__ that step in when I want to define metadata.

Of course I could remap SA properties to 'internal' properties (e.g. tests.c.id to Prova._id) but this leads to name changes even when querying the DB, and that's something I don't like.

Now, I don't know how should I proceed to do this without making damage to the whole SA 'system'. Of course if I make changes to UOWProperty class code, but I think it wouldn't be a good way to deal with the problem, since it's hard that such a mod would make it into the standard SA code and I'd need to manage it across version changes and updates.

I'd like a way to define a 'special mapper' which reads which additional attributes I'd like to be defined and attachs the matching custom-defined properties to the mapped class. My Test class would like something like that:


class Test(object):
    _extra_column_attrs["hidden": False, "readonly":False]
    _hidden_cols = ("id", )
    _readonly_cols = ("readonly",)

My final question hence is... how can I write a custom mapper which uses custom defined properties? I suppose I can inherit the Mapper class and tweak it, but I tried to crawl into SA sources but it's not to clear to me where I could change something in order to get such an effect.

Thanks!




--
Alan Franzoni <[EMAIL PROTECTED]>
-
Togli .xyz dalla mia email per contattarmi.
Remove .xyz from my address in order to contact me.
-
GPG Key Fingerprint (Key ID = FE068F3E):
5C77 9DC3 BD5B 3A28 E7BC 921A 0255 42AA FE06 8F3E
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to