Skip to main content

Summary

Groups and multi-user account management

Author

Ben Lopatin (http://benlopatin.com)

Status

Documentation Status PyPI Package latest release PyPI Wheel Supported versions Supported implementations

Separate individual user identity from accounts and subscriptions. Django Organizations adds user-managed, multi-user groups to your Django project. Use Django Organizations whether your site needs organizations that function like social groups or multi-user account objects to provide account and subscription functionality beyond the individual user.

  • Works with your existing user model, whether django.contrib.auth or a custom model. No additional user or authentication functionality required.

  • Users can be belong to and own more than one organization (account, group)

  • Invitation and registration functionality works out of the box for many situations and can be extended as need to fit specific requirements.

  • Start with the base models or use your own for greater customization.

Documentation is on Read the Docs

Development & Contributing

The master branch represents version 2 development. For updates related to 1.x versions of django-organizations pull requests should be made against the [`version-1.x` branch](tree/version-1.x).

Development is on-going. To-do items have been moved to the wiki for the time being.

The basic functionality should not need much extending. Current dev priorities for me and contributors should include:

  • Improving the tests and test coverage (ideally moving them back out of the main module and executable using the setup.py file)

  • Improving the backends and backends concept so that additional invitation and registration backends can be used

  • Documentation

  • Ensuring all application text is translatable

Please use the project’s issues tracker to report bugs, doc updates, or other requests/suggestions.

Targets & testing

The codebase is targeted and tested against:

  • Django 3.2.x against Python 3.8, 3.9, 3.10

  • Django 4.1.x against Python 3.8, 3.9, 3.10, 3.11

  • Django 4.2.x against Python 3.8, 3.9, 3.10, 3.11

To run the tests against all target environments, install tox and then execute the command:

tox

Fast testing

Testing each change on all the environments takes some time, you may want to test faster and avoid slowing down development by using pytest against your current environment:

pip install -r requirements-test.txt
py.test

Supply the -x option for failfast mode:

py.test -x

Submitting

These submission guidelines will make it more likely your submissions will be reviewed and make it into the project:

  • Ensure they match the project goals and are sufficiently generalized

  • Please try to follow Django coding style. The code base style isn’t all up to par, but I’d like it to move in that direction

  • Also please try to include good commit log messages.

  • Pull requests should include an amount of code and commits that are reasonable to review, are logically grouped, and based off clean feature branches.

Code contributions are expected to pass in all target environments, and pull requests should be made from branches with passing builds on GitHub Actions.

Project goals

django-organizations should be backend agnostic:

  1. Authentication agnostic

  2. Registration agnostic

  3. Invitation agnostic

  4. User messaging agnostic

Etc.

Installing

First add the application to your Python path. The easiest way is to use pip:

pip install django-organizations

Check the Release History tab on the PyPI package page for pre-release versions. These can be downloaded by specifying the version.

You can also install by downloading the source and running:

$ python setup.py install

By default you will need to install django-extensions or comparable libraries if you plan on adding Django Organizations as an installed app to your Django project. See below on configuring.

Configuring

Make sure you have django.contrib.auth installed, and add the organizations application to your INSTALLED_APPS list:

INSTALLED_APPS = (
    ...
    'django.contrib.auth',
    'organizations',
)

Then ensure that your project URL conf is updated. You should hook in the main application URL conf as well as your chosen invitation backend URLs:

from organizations.backends import invitation_backend

urlpatterns = [
    ...
    url(r'^accounts/', include('organizations.urls')),
    url(r'^invitations/', include(invitation_backend().get_urls())),
]

Auto slug field

The standard way of using Django Organizations is to use it as an installed app in your Django project. Django Organizations will need to use an auto slug field which are not included. By default it will try to import these from django-extensions, but you can configure your own in settings. The default:

ORGS_SLUGFIELD = 'django_extensions.db.fields.AutoSlugField'

Alternative:

ORGS_SLUGFIELD = 'autoslug.fields.AutoSlugField'

Previous versions allowed you to specify an ORGS_TIMESTAMPED_MODEL path. This is now ignored and the functionality satisfied by a vendored solution. A warning will be given but this should not have any effect on your code.

Registration & invitation backends

You can specify a different invitation backend in your project settings, and the invitation_backend function will provide the URLs defined by that backend:

INVITATION_BACKEND = 'myapp.backends.MyInvitationBackend'

Usage Overview

For most use cases it should be sufficient to include the app views directly using the default URL conf file. You can customize their functionality or access controls by extending the base views.

There are three models:

  • Organization The group object. This is what you would associate your own app’s functionality with, e.g. subscriptions, repositories, projects, etc.

  • OrganizationUser A custom through model for the ManyToMany relationship between the Organization model and the User model. It stores additional information about the user specific to the organization and provides a convenient link for organization ownership.

  • OrganizationOwner The user with rights over the life and death of the organization. This is a one to one relationship with the OrganizationUser model. This allows User objects to own multiple organizations and makes it easy to enforce ownership from within the organization’s membership.

The underlying organizations API is simple:

>>> from organizations.utils import create_organization
>>> chris = User.objects.get(username="chris")
>>> soundgarden = create_organization(chris, "Soundgarden", org_user_defaults={'is_admin': True})
>>> soundgarden.is_member(chris)
True
>>> soundgarden.is_admin(chris)
True
>>> soundgarden.owner.organization_user
<OrganizationUser: Chris Cornell>
>>> soundgarden.owner.organization_user.user
>>> <User: chris>
>>> audioslave = create_organization(chris, "Audioslave")
>>> tom = User.objects.get(username="tom")
>>> audioslave.add_user(tom, is_admin=True)
<OrganizationUser: Tom Morello>

Custom models

Django-organizations can act as a base library (not installed in your project) and used to create unique organization model sets using custom tables. See the Cooking with Django Organizations section in the documentation for advice on proceeding.

License

Anyone is free to use or modify this software under the terms of the BSD license.

Sponsors

Muster is building precision advocacy software to impact policy through grassroots action.

Alternative text

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-organizations-2.2.0.tar.gz (31.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_organizations-2.2.0-py2.py3-none-any.whl (46.0 kB view details)

Uploaded Python 2Python 3

File details

Details for the file django-organizations-2.2.0.tar.gz.

File metadata

  • Download URL: django-organizations-2.2.0.tar.gz
  • Upload date:
  • Size: 31.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for django-organizations-2.2.0.tar.gz
Algorithm Hash digest
SHA256 b8a93e7105695502f8dd2f7b4038d5cf356d15fcf29089eebb068b3139948d5e
MD5 3189ec1e56672b3097ac1f15a284f545
BLAKE2b-256 11f12ad4445ea6146e5c33e3f6ad6843e67a9559eaa57e6a178602d97627362b

See more details on using hashes here.

File details

Details for the file django_organizations-2.2.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for django_organizations-2.2.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 c8d55a339a3bf6ee814b21fb31adf9540ced1eb1ffd1cfb60d607dd951feee1f
MD5 c0a749f7c29c87a4c2512ee9f8cee134
BLAKE2b-256 5b0067320cade41acd0d3bba704a4f2cd5f99035a46f46c8559d8b909d421fb6

See more details on using hashes here.

Release history Release notifications | RSS feed

2.7.0

2 files

2.6.0

2 files

2.5.0

2 files

2.4.1

2 files

2.3.1

2 files

2.3.0

2 files

This release

2.2.0 This release

2 files

2.1.0

2 files

2.0.2

2 files

2.0.1

2 files

2.0.0

2 files

1.1.2

2 files

1.1.1

2 files

1.1.0

2 files

1.0.0

2 files

0.9.3

2 files

0.9.2

2 files

0.9.1

2 files

0.9.0

2 files

0.8.2

2 files

0.8.1

2 files

0.8.0

2 files

0.7.0

2 files

0.6.1

2 files

0.6.0

2 files

0.5.3

2 files

0.5.2

2 files

0.5.1

2 files

0.5.0

2 files

0.4.3

2 files

0.4.2

2 files

0.4.1

2 files

0.4.0

2 files

0.3.0

2 files

0.2.3

2 files

0.2.2

2 files

0.2.1

2 files

0.2.0

2 files

0.1.10

1 file

0.1.9

1 file

0.1.8

1 file

0.1.7

1 file

0.1.6

1 file

0.1.5

1 file

0.1.4

1 file

0.1.3

1 file

0.1.2

1 file

0.1.1

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page