bernardopires / django-tenant-schemas

Tenant support for Django using PostgreSQL schemas.
https://django-tenant-schemas.readthedocs.org/en/latest/
MIT License
1.46k stars 424 forks source link

Using `TenantStorageMixin ` with `django-storages` #565

Open veeral-patel opened 6 years ago

veeral-patel commented 6 years ago

Hi all!

So I want to use django-storages to store my static and media files in a Google Cloud Storage bucket.

Currently, I have this line in my settings.py:

DEFAULT_FILE_STORAGE = 'storages.backends.gcloud.GoogleCloudStorage'

I understand I need to add TenantStorageMixin to this GoogleCloudStorage backend. Is there an easy way of doing this without modifying my local django-storages code to make it inherit from TenantStorageMixin as well?

I do need to use Google Cloud Storage, but I don't need to use django-storages. So if you have an alternative backend for storing tenant data with django-tenant-schemas, please let me know too!

mikicz commented 6 years ago

Hi,

you can make your own subclass of the GoogleCloudStorage class to then set to DEFAULT_FILE_STORAGE.

from storages.backends.gcloud import GoogleCloudStorage
from tenant_schemas.storage import TenantStorageMixin

class TenantGoogleCloudStorage(TenantStorageMixin, GoogleCloudStorage):
    pass 

And then set

DEFAULT_FILE_STORAGE = 'path.to.storage.TenantGoogleCloudStorage'
veeral-patel commented 6 years ago

Thank you @mikicz! I'll try this out! Feel free to close.

alexandernst commented 6 years ago

Maybe add this somewhere in the docs, as it really sounds quite useful. Maybe also another example for settings cookies/session/cache storage?