用户创建的动态数据库 - django [英] dynamic databases created by users - django

查看:93
本文介绍了用户创建的动态数据库 - django的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个用户可以登录并创建自己的数据库的网站(也可以操纵它们)。这些数据库将非常小,主要用于测试。阅读建议 这里的解决方案 在SO上似乎我有几个选项:




  • 使用预定义的功能将数据库动态添加到settings.py(如建议here )。我发现这是一个非常糟糕的主意,因为它似乎是一个黑客,并暴露了你自己的settings.py文件。

  • 将SQlite文件存储在媒体中,并连接给他们使用django.db.connections。这似乎是一个合理的解决方案,虽然我不知道如何执行它。

  • 不要使用实际的数据库,而是使用XML或其他格式存储信息,这可能会花费我的效率

  • 我自己的想法,这可能是疯狂的愚蠢 - 将SQlite文件存储在MySQL数据库内的blob。



最终目标是允许用户在网站上创建django模型,然后对它们执行查询(这是一个学习网站)。有任何想法吗?

解决方案

使用面料稍微多于伪代码:)

 从fabric import api 

def django_start_project(project_name):
api.run('mkproject%s'%project_name)#假设你有virtualenvwrapper
与api.prefix('workon%s'%project_name):
api.run('pip install django')
api.run('django-admin.py startproject')

最后一部分当然需要一些工作,但这是要点:)



如下所示:

  fab django_start_project:your_project 
/ pre>

依赖关系:




I want to create a website where users can log in and create their own database (and also be able to manipulate them). These databases will be very small, and are ment to be used for testing mostly. Reading the suggested solutions here on SO it seems I have a few options:

  • dynamically add database to settings.py using a pre-defined functionality (as suggested here). I find this to be a very bad idea since it seems like a hack and exposes your own settings.py file.
  • store SQlite files in media, and connect to them using django.db.connections. This seems like a reasonable solution, though I have no idea how to execute it.
  • don't use an actual database but an XML or some other format for storing information, which will probably cost me in efficiency
  • my own idea, which might be crazy stupid - store SQlite files as blobs inside MySQL database.

The end-goal is to allow the users to create django models on the website and then perform queries on them (it's a learning website). Any ideas?

解决方案

Slightly more than pseudocode, using fabric :)

from fabric import api

def django_start_project(project_name):
    api.run('mkproject %s' % project_name)  # Assumes you have virtualenvwrapper
    with api.prefix('workon %s' % project_name):
        api.run('pip install django')
        api.run('django-admin.py startproject')

The last part needs some work of course, but this is the gist :)

Called like this:

fab django_start_project:your_project

Dependencies:

这篇关于用户创建的动态数据库 - django的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆