-
Notifications
You must be signed in to change notification settings - Fork 424
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #392 from filipeximenes/utils-docs
Added documentation for 'utils' module
- Loading branch information
Showing
2 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,6 +53,7 @@ Contents | |
use | ||
examples | ||
templates | ||
utils | ||
test | ||
involved | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||