Skip to content

Commit

Permalink
Merge pull request #392 from filipeximenes/utils-docs
Browse files Browse the repository at this point in the history
Added documentation for 'utils' module
  • Loading branch information
bernardopires committed Oct 3, 2016
2 parents 0a9583e + fb2ec81 commit 7ddba7a
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Contents
use
examples
templates
utils
test
involved

46 changes: 46 additions & 0 deletions docs/utils.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
=====
Utils
=====

.. function:: schema_context(schema_name)

This is a context manager. Database queries performed inside it will be executed in against the passed ``schema_name``.

.. code-block:: python
from tenant_schemas.utils import schema_context
from django.auth.models import User
with schema_context('some_tenant'):
users = User.objects.all()
print(users)
.. function:: tenant_context(tenant)

Same as ``schema_context`` but this time a tenant must be passed.

.. code-block:: python
from tenant_schemas.utils import tenant_context, get_tenant_model
from django.auth.models import User
tenant = get_tenant_model().objects.get(schema_name='some_tenant')
with tenant_context(tenant):
users = User.objects.all()
print(users)
.. function:: get_tenant_model()

Returns the tenant model.

.. code-block:: python
from tenant_schemas.utils import get_tenant_model
tenant = get_tenant_model().objects.get(schema_name='some_tenant')
print(tenant.domain_url)

0 comments on commit 7ddba7a

Please sign in to comment.