Git Product home page Git Product logo

django-tenancy's People

Contributors

cgranetgithub avatar charettes avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

django-tenancy's Issues

User authentication module?

Which is the best user authentication module to use with django-tenancy? I've used userena and looking at django-allauth.

Thread-safe?

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?

objects.get and DoesNotExist?

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?

onetoonefield to tenant

Hi,

Which approach you recommend to models that were onetoonefield to a tenant?

Thank you very much in advance.

Best regards,

Alberto

'unicode' object has no attribute '_default_manager'

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)

ImportError: cannot import name create_superuser Django 1.7

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

Make sure schema creation signals are always loaded.

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.

One-to-one relationship not working as expected

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!

related fields tenant not updated

Lets suppose this

tenant.name ='new name'
tenant.save()
tenant.specificmodel_set.first().tenant.name != tenant.name

Any explanation?

README with overview, design goals and simple examples

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.

Object with generic relations fails delete

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?

Fix deprecation warnings on Django 1.10

  • Use _meta.private_fields instead of virtual_fields.
  • Pass private=True instead of virtual=True in Field.contribute_to_class().
  • Investigate what can be done in regards to concrete model manager inheritance changes.
  • Investigate what can be done in regards to use_for_related_fields and _meta.base_manager_name.

Migrations not working

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!!

Getting started

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?

Documentation

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.