charettes / django-tenancy Goto Github PK
View Code? Open in Web Editor NEWHandle multi-tenancy in Django with no additional global state using schemas.
Home Page: http://pypi.python.org/pypi/django-tenancy
Handle multi-tenancy in Django with no additional global state using schemas.
Home Page: http://pypi.python.org/pypi/django-tenancy
Hi, calling remove_from_apps_registry from https://github.com/charettes/django-tenancy/blob/django-1.7/tenancy/models.py#L265
creates a dead_lock in D1.7 because the lock in
https://github.com/charettes/django-tenancy/blob/django-1.7/tenancy/utils.py#L67
is still locked from apps.populate()
Any workaround we can make?
Best regards,
Alberto
Which is the best user authentication module to use with django-tenancy? I've used userena and looking at django-allauth.
If request
is specified the tenant should be tentatively retrieved from it.
The following will raised an exception.
class A(TenantModel):
pass
class B(TenantModel):
a = models.ForeignKey(A, related_name='b_set')
a = A.objects.create()
a.b_set.only('a').get() # <- Cannot assign a to ...
I'm currently evaluating multi-tenant solutions and have been looking at django-tenant-schemas however there is a concern that the aforementioned project is not thread-safe when creating new tenants bernardopires/django-tenant-schemas#2. Can you comment on the thread safety of creating new tenants using this package?
I'm trying to retrieve an object based on primary key and that works! However, if I specify a primary key that doesn't exist it's not throwing any exception I can catch, e.g.:
app = Application.for_tenant(request.tenant).objects.get(pk=appid)
Ideas?
Hi,
Which approach you recommend to models that were onetoonefield to a tenant?
Thank you very much in advance.
Best regards,
Alberto
Hi, It is weird, I got these errors when working with FK to tenant models...
get_context_data
print PermissionRole.for_tenant(self.request.tenant).objects.filter()
File ".virtualenvs/bw/lib/python2.7/site-packages/django/db/models/query.py", line 119, in __repr__
return repr(data)
File ".virtualenvs/bw/lib/python2.7/site-packages/django/db/models/base.py", line 459, in __repr__
u = six.text_type(self)
File "src/bw/appointments/models.py", line 150, in __unicode__
unicode(self.role),
File ".virtualenvs/bw/lib/python2.7/site-packages/django/db/models/fields/related.py", line 564, in __get__
qs = self.get_queryset(instance=instance)
File ".virtualenvs/bw/lib/python2.7/site-packages/django/db/models/fields/related.py", line 509, in get_queryset
rel_mgr = self.field.rel.to._default_manager.db_manager(hints=hints)
AttributeError: 'unicode' object has no attribute '_default_manager'
I've defined
role = models.ForeignKey(Role)
Hi,
Executing python manage.py createtenant
I got the following error:
Traceback (most recent call last):
....
File "/lib/python2.7/site-packages/tenancy/management/commands/createtenant.py", line 37, in handle
tenant_model = get_tenant_model()
File "/lib/python2.7/site-packages/tenancy/__init__.py", line 11, in get_tenant_model
from .settings import TENANT_MODEL
File "/lib/python2.7/site-packages/tenancy/settings.py", line 4, in <module>
from django.contrib.auth.management import create_superuser
ImportError: cannot import name create_superuser
At the moment the tenancy.management
module is not loaded thus not schema nor tables are created.
The workaround is to import the management module manually somehow:
from tenancy import management as _management # Workaround until version 0.1.1 is released.
I'm having some weird behaviors when trying to use a one-to-one relationship and I'm not sure if this is a bug or if I am doing something wrong.
Let's say I have the following models:
class Tenant(AbstractTenant):
name = models.CharField(max_length=50)
def natural_key(self):
return (self.name, )
class A(TenantModel):
name = models.CharField(max_length=30)
class B(TenantModel):
main = models.OneToOneField(A)
name = models.CharField(max_length=40)
And I try to run the following on the django shell:
from core.models import Tenant, A, B
t, _ = Tenant.objects.get_or_create(name='tenant1')
a_model = A.for_tenant(t)
a_model.objects.filter(b__name='test')
Then I get an exception: django.core.exceptions.FieldError: Cannot resolve keyword 'b' into field. Choices are: id, name
If I try to access this reverse relationship directly through an instance of A with something like a_model.objects.first().b
, then I get this exception: django.db.utils.ProgrammingError: relation "core_b" does not exist LINE 1: ...b"."id", "core_b"."main_id", "core_b"."name" FROM "core_b" W...
But if I simply access the tenant model for B in this shell session with b_model = B.for_tenant(t)
then things start behaving differently:
Running a_model.objects.filter(b__name='test')
now gets me django.core.exceptions.FieldError: Cannot resolve keyword 'b' into field. Choices are: b_set, id, name
, which says to me that there is now a b_set
relationship (but I think it should be named b
only, since this is an OneToOneField
) and I can filter it with no errors with a_model.objects.filter(b_set__name='test')
. It should be noted that before accessing the B
tenant model the same command does not work at all.
Other similar strange behaviors happen when I try to access b_set
on an A
instance before running B.for_tenant(t)
.
It seems that this affects ForeignKey
fields also, but I just looked briefly at it.
Am I missing something? I am using Django 1.10.2, by the way.
Thanks!
I am trying to use this library with django 1.7 and it is failing in different points.
Any expectation to make it compatible?
Lets suppose this
tenant.name ='new name'
tenant.save()
tenant.specificmodel_set.first().tenant.name != tenant.name
Any explanation?
Congrats on the new repo @charettes :)
Requesting a README.md (or .rst) that provides users (and future contributors) some background and context behind django-tenancy
I'm sure future repo stargazers would be interested in a conceptual summary of the problem domain that the project aims to address, as well as it's design goals. A few use-case examples might prove useful too.
We should be able to achieve this by subclassing it and removing it from it's parents. This would fix the fugly __super
workaround.
Hi, exception below:
...
self.object.delete()
File "/Users/arescope/.virtualenvs/bw/lib/python2.7/site-packages/django/db/models/base.py", line 740, in delete
collector.delete()
File "/Users/arescope/.virtualenvs/bw/lib/python2.7/site-packages/django/db/models/deletion.py", line 262, in delete
qs._raw_delete(using=self.using)
File "/Users/arescope/.virtualenvs/bw/lib/python2.7/site-packages/django/db/models/query.py", line 569, in _raw_delete
sql.DeleteQuery(self.model).delete_qs(self, using)
File "/Users/arescope/.virtualenvs/bw/lib/python2.7/site-packages/django/db/models/sql/subqueries.py", line 85, in delete_qs
self.get_compiler(using).execute_sql(NO_RESULTS)
File "/Users/arescope/.virtualenvs/bw/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 786, in execute_sql
cursor.execute(sql, params)
File "/Users/arescope/.virtualenvs/bw/lib/python2.7/site-packages/debug_toolbar/panels/sql/tracking.py", line 174, in execute
return self._record(self.cursor.execute, sql, params)
File "/Users/arescope/.virtualenvs/bw/lib/python2.7/site-packages/debug_toolbar/panels/sql/tracking.py", line 104, in _record
return method(sql, params)
File "/Users/arescope/.virtualenvs/bw/lib/python2.7/site-packages/django/db/backends/utils.py", line 81, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "/Users/arescope/.virtualenvs/bw/lib/python2.7/site-packages/django/db/backends/utils.py", line 65, in execute
return self.cursor.execute(sql, params)
File "/Users/arescope/.virtualenvs/bw/lib/python2.7/site-packages/django/db/utils.py", line 94, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/Users/arescope/.virtualenvs/bw/lib/python2.7/site-packages/django/db/backends/utils.py", line 65, in execute
return self.cursor.execute(sql, params)
the declaration in the model is
documents = GenericRelation('documents.Document',
content_type_field='owner_content_type',
object_id_field='owner_id')
Any clue? overriding delete method?
_meta.private_fields
instead of virtual_fields
.private=True
instead of virtual=True
in Field.contribute_to_class()
.use_for_related_fields
and _meta.base_manager_name
.If I add/remove a field to a TenantModel, it is not propagated to the schemas.
It might me because the models are not managed.
Shall the migrate command be wrapped to work with the schemas? Any idea??
Thanks!!
I'm getting an error trying to set TENANCY_TENANT_MODEL. Here's my project structure:
myapp
hosts.py
settings.py
urls.py
wsgi.py
tenant
admin.py
models.py (MyTenantModel defined in here)
views.py
In my settings.py I am specifying:
from tenant import models
TENANCY_TENANT_MODEL=models.MyTenantModel
But I am receiving this error when running syncdb:
ImportError: Could not import settings 'my app.settings' (Is it on sys.path? Is there an import error in the settings file?): cannot import name models
Can you assist?
It looks like there is a tremendous amount of functionality in this module, however there is very little documentation. An example project would be extremely helpful. I would especially like to see how to use the Views to achieve separation of tenants.
-pip install django-tenany
+pip install django-tenancy
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.