1

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?

Community
  • 1
  • 1
yuvi
  • 18,155
  • 8
  • 56
  • 93
  • How about another option, just create a new Django project per user with it's own virtualenv and own sqlite database so you have full separation? – Wolph Jan 25 '14 at 10:33
  • That's not a bad idea. If you can expand this with some pseudo-code even I might mark it as the answer – yuvi Jan 25 '14 at 10:48

1 Answers1

3

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:

Wolph
  • 78,177
  • 11
  • 137
  • 148
  • I never heard of fabric before. Incredible. I still need to find a way to create the virtualenv though, right? I can't use fabric for that (or can I?) – yuvi Jan 27 '14 at 09:33
  • The example above already creates the virtualenv if you install and set up virtualenv and virtualenvwrapper. The `mkproject` is a virtualenvwrapper command which creates a new directory in your `PROJECT_HOME` and a virtualenv in your `WORKON_HOME`. Docs: http://virtualenvwrapper.readthedocs.org/en/latest/command_ref.html#command-mkproject – Wolph Jan 27 '14 at 10:12
  • Oh. I assumed you meant it literally - a virtualenv which serves as a wrapper, I didn't know there was actually a python module with that name, Heh. Fantastic, I'll dive right into it – yuvi Jan 27 '14 at 10:36