mirror of
https://github.com/jazzband/dj-database-url.git
synced 2026-05-11 08:43:14 +00:00
new style
This commit is contained in:
parent
fb6af9c4e6
commit
7462e79d51
3 changed files with 11 additions and 14 deletions
|
|
@ -11,7 +11,7 @@ Usage
|
|||
|
||||
Configure your database in ``settings.py``::
|
||||
|
||||
DATABASES = dj_database_url.config(DATABASES)
|
||||
DATABASES['default'] = dj_database_url.config()
|
||||
|
||||
Nice and simple.
|
||||
|
||||
|
|
|
|||
|
|
@ -7,21 +7,18 @@ import urlparse
|
|||
urlparse.uses_netloc.append('postgres')
|
||||
urlparse.uses_netloc.append('mysql')
|
||||
|
||||
DEFAULT_ENV = 'DATABASE_URL'
|
||||
|
||||
def config(config=None):
|
||||
def config(env=DEFAULT_ENV):
|
||||
"""Returns configured DATABASES dictionary."""
|
||||
|
||||
if config is None:
|
||||
config = {}
|
||||
config = {}
|
||||
|
||||
if 'DATABASE_URL' in os.environ:
|
||||
url = urlparse.urlparse(os.environ['DATABASE_URL'])
|
||||
|
||||
# Ensure default database exists.
|
||||
config.setdefault('default', {})
|
||||
if env in os.environ:
|
||||
url = urlparse.urlparse(os.environ[env])
|
||||
|
||||
# Update with environment configuration.
|
||||
config['default'].update({
|
||||
config.update({
|
||||
'NAME': url.path[1:],
|
||||
'USER': url.username,
|
||||
'PASSWORD': url.password,
|
||||
|
|
@ -30,9 +27,9 @@ def config(config=None):
|
|||
})
|
||||
|
||||
if url.scheme == 'postgres':
|
||||
config['default']['ENGINE'] = 'django.db.backends.postgresql_psycopg2'
|
||||
config['ENGINE'] = 'django.db.backends.postgresql_psycopg2'
|
||||
|
||||
if url.scheme == 'mysql':
|
||||
config['default']['ENGINE'] = 'django.db.backends.mysql'
|
||||
config['ENGINE'] = 'django.db.backends.mysql'
|
||||
|
||||
return config
|
||||
4
setup.py
4
setup.py
|
|
@ -13,7 +13,7 @@ Usage
|
|||
|
||||
Configure your database in ``settings.py``::
|
||||
|
||||
DATABASES = dj_database_url.config(DATABASES)
|
||||
DATABASES['default'] = dj_database_url.config()
|
||||
|
||||
Nice and simple.
|
||||
|
||||
|
|
@ -23,7 +23,7 @@ from setuptools import setup
|
|||
|
||||
setup(
|
||||
name='dj-database-url',
|
||||
version='0.1.0',
|
||||
version='0.1.1',
|
||||
url='https://github.com/kennethreitz/dj-database-url',
|
||||
license='BSD',
|
||||
author='Kenneth Reitz',
|
||||
|
|
|
|||
Loading…
Reference in a new issue