SQLAlchemy and django, is it production ready?

后端 未结 5 963
鱼传尺愫
鱼传尺愫 2020-12-04 22:25

Has anyone used SQLAlchemy in addition to Django\'s ORM?

I\'d like to use Django\'s ORM for object manipulation and SQLalchemy for complex

相关标签:
5条回答
  • 2020-12-04 22:48

    Jacob Kaplan-Moss admitted to typing "import sqlalchemy" from time to time. I may write a queryset adapter for sqlalchemy results in the not too distant future.

    0 讨论(0)
  • 2020-12-04 22:52

    Nowadays you can use Aldjemy. Consider using this tutorial.

    0 讨论(0)
  • 2020-12-04 22:55

    I don't think it's good practice to use both. You should either:

    1. Use Django's ORM and use custom SQL where Django's built-in SQL generation doesn't meet your needs, or
    2. Use SQLAlchemy (which gives you finer control at the price of added complexity) and, if needed, use a declarative layer such as Elixir to make life a little easier.

    Of course, if you need Django's admin, then the first of these approaches is recommended.

    0 讨论(0)
  • 2020-12-04 22:59

    I've done it before and it's fine. Use the SQLAlchemy feature where it can read in the schema so you don't need to declare your fields twice.

    You can grab the connection settings from the settings, the only problem is stuff like the different flavours of postgres driver (e.g. with psyco and without).

    It's worth it as the SQLAlchemy stuff is just so much nicer for stuff like joins.

    0 讨论(0)
  • 2020-12-04 23:04

    What I would do,

    1. Define the schema in Django orm, let it write the db via syncdb. You get the admin interface.

    2. In view1 you need a complex join

    
        def view1(request):
           import sqlalchemy
           data = sqlalchemy.complex_join_magic(...)
           ...
           payload = {'data': data, ...}
           return render_to_response('template', payload, ...)
    
    
    0 讨论(0)
提交回复
热议问题