From a022bb04a5f855639689360de6a1e65ea4e11074 Mon Sep 17 00:00:00 2001 From: Parth Shandilya Date: Tue, 21 Jan 2020 20:27:09 +0100 Subject: [PATCH] Clarify the usage example in the docs --- README.rst | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/README.rst b/README.rst index a9cf2aa..079118d 100644 --- a/README.rst +++ b/README.rst @@ -31,20 +31,38 @@ Installation is simple:: Usage ----- -Configure your database in ``settings.py`` from ``DATABASE_URL``:: +1. If ``DATABASES`` is already defined: + +- Configure your database in ``settings.py`` from ``DATABASE_URL``:: import dj_database_url DATABASES['default'] = dj_database_url.config(conn_max_age=600) -Provide a default:: +- Provide a default:: DATABASES['default'] = dj_database_url.config(default='postgres://...') -Parse an arbitrary Database URL:: +- Parse an arbitrary Database URL:: DATABASES['default'] = dj_database_url.parse('postgres://...', conn_max_age=600) +2. If ``DATABASES`` is not defined: + +- Configure your database in ``settings.py`` from ``DATABASE_URL``:: + + import dj_database_url + + DATABASES = {'default': dj_database_url.config(conn_max_age=600)} + +- Provide a default:: + + DATABASES = {'default': dj_database_url.config(default='postgres://...')} + +- Parse an arbitrary Database URL:: + + DATABASES = {'default': dj_database_url.parse('postgres://...', conn_max_age=600)} + The ``conn_max_age`` attribute is the lifetime of a database connection in seconds and is available in Django 1.6+. If you do not set a value, it will default to ``0`` which is Django's historical behavior of using a new database connection on each