bennylope / django-organizations

:couple: Multi-user accounts for Django projects
http://django-organizations.readthedocs.org/
BSD 2-Clause "Simplified" License
1.31k stars 212 forks source link

Using this package just for abstract models #204

Closed iMerica closed 3 years ago

iMerica commented 4 years ago

Hi,

Is there a way I can leverage the abstract base classes of this package to extend my existing models? Currently the documentation suggest adding organizations to INSTALLED_APPS but this creates organization_organization tables. I want these models/tables to be in my own app.

iMerica commented 4 years ago

When I attempt to only use the classes without adding it to INSTALLED_APPS in this package, I see

Traceback (most recent call last):
  File "./manage.py", line 15, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python3.8/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python3.8/site-packages/django/core/management/__init__.py", line 377, in execute
    django.setup()
  File "/usr/local/lib/python3.8/site-packages/django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/usr/local/lib/python3.8/site-packages/django/apps/registry.py", line 114, in populate
    app_config.import_models()
  File "/usr/local/lib/python3.8/site-packages/django/apps/config.py", line 211, in import_models
    self.models_module = import_module(models_module_name)
  File "/usr/local/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 783, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/app/mypp/core/models.py", line 21, in <module>
    from organizations.models import AbstractOrganization, AbstractOrganizationUser
  File "/usr/local/lib/python3.8/site-packages/organizations/models.py", line 32, in <module>
    class Organization(AbstractOrganization):
  File "/usr/local/lib/python3.8/site-packages/organizations/base.py", line 79, in __new__
    model = super(OrgMeta, cls).__new__(cls, name, bases, attrs)
  File "/usr/local/lib/python3.8/site-packages/django/db/models/base.py", line 113, in __new__
    raise RuntimeError(
RuntimeError: Model class organizations.models.Organization doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.
ZeroCoolHacker commented 4 years ago

You have to treat it as a separate library. And import the abstract models from it.