Ben, I contemplated something like this, but I assumed that field properties would clash. For instance, after the call to mapper(...) you would no longer have access to Django ORM fields with the Model.field syntax (as they would be replaced by SA's). So what I did was this:
To get Django models: from django.contrib.auth.models import User To get SA models: from tranquil.models.auth import User The other thing I wasn't so sure about in combining the two is if that would require each page view to grab 2 connections to the db. Once for the Django ORM and once for the SA ORM. There's a lot of implicit stuff I haven't totally groked (specifically, if the connection grabbing is lazy or not) Anyway, I'm gonna take a closer look at the project the Jeroen guy is working on to see how it works and if there's anything I can use. Judging by reading through the description at the URL you posted it seems quite a bit more clunky to use, but he does do some of the things I had initially planned on doing. Thanks for the heads on the project. I hadn't heard of it. Paul Davis On 10/4/07, Ben Ford <[EMAIL PROTECTED]> wrote: > Hi Paul, > > I'd love to have time to play with this, but I don't at the moment. It's > something I've been interested in for a while though, and also something > that I want to take a long hard look at pretty soon. Have you seen: > http://jeroen.concept-q.com/projects/djangoalchemy/? Maybe > something you could look at in the spirit of DRY if you're both doing the > same thing. > > How do you feel about mapping Tables directly to django Models...? I.E: > > db_table = <your_model>._meta.db_table > sastring = <connection string for your db> (I have a function to build this > from settings.py ) > engine = create_engine(sastring) > sa_table = Table(db_table, engine, autoload=True) > mapper(<your_model>, sa_table) > > You can now use <your_model>.c to get access to all of the SA stuff, and do > funky things with joins and what-not that you can't with django ORM. But all > of the objects that the resulting query returns are Model instances so all > of your django functionality (admin, etc) still works. This is kinda off the > top of my head, and I've only used it superficially with no testing at all, > but on first inspection it appears to work. what do you think? > > Ben > > > On 05/10/2007, Paul Davis <[EMAIL PROTECTED]> wrote: > > > > > > Before anyone gets to excited, I'm going to state up front that I have > > *not* replaced django's ORM. > > > > But I do have a small project that gives proof of concept for > > automatically integrating SQL Alchemy ORM into the Django ORM. I've > > been kicking the idea around for a bit, and after going through the > > code I felt it was fairly hopeless to actually try and replace the > > entire Django ORM with an sqlalchemy back end. > > > > Major key points: (remember this is PoC so suggestions are indeed welcome) > > > > SA = SQLAlchemy > > > > 1. SA creates its Table objects using reflection > > 2. SA ORM classes are dynamically created > > 3. SA ORM classes are directly importable via tranquil.models.* > > 4. I haven't got the ability to fully configure the setup of SA > > tables, ORM classes, and mappers yet. This is planned, but I felt like > > it wasn't important for PoC > > 5. Currently, SA reflection happens every time the server starts. > > Obviously, caching this is on the ToDo list > > 6. All of this is provided by an external app with no patches to Django > itself. > > > > Project Page: http://code.google.com/p/tranquil/ > > Example views.py: > > > http://tranquil.googlecode.com/svn/trunk/proj_name/app_name/views.py > > > > Basic usage: > > Assuming tranquil is in the installed apps, just do: > > > > from tranquil.models.app_name import ModelName > > > > ModelName is the SQLAlchemy ORM object which means its pure SQLAlchemy > > from there. > > > > Any feedback is welcome. If there's enough interest I'll move forward > > with filling out the corners. > > > > Thanks, > > Paul Davis > > > > [EMAIL PROTECTED] > > +6281317958862 > > > > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-developers?hl=en -~----------~----~----~----~------~----~------~--~---