Package: django-organizations
SummaryGroups and multi-user account managementAuthorBen Lopatin (http://benlopatin.com)StatusSeparate 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, whetherdjango.contrib.author 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 onRead the DocsDevelopment & ContributingThe 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 usedDocumentationEnsuring all application text is translatablePlease use the project’s issues tracker to report bugs, doc updates, or other
requests/suggestions.Targets & testingThe codebase is targeted and tested against:Django 3.2.x against Python 3.8, 3.9, 3.10Django 4.1.x against Python 3.8, 3.9, 3.10, 3.11Django 4.2.x against Python 3.8, 3.9, 3.10, 3.11To run the tests against all target environments, installtoxand then execute the command:toxFast testingTesting 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.testSupply the-xoption forfailfastmode:py.test -xSubmittingThese 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 generalizedPlease try to followDjango coding style.
The code base style isn’t all up to par, but I’d like it to move in that
directionAlso please try to includegood commit log messages.Pull requests should include an amount of code and commits that are
reasonable to review, arelogically 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 onGitHub Actions.Project goalsdjango-organizations should be backend agnostic:Authentication agnosticRegistration agnosticInvitation agnosticUser messaging agnosticEtc.InstallingFirst add the application to your Python path. The easiest way is to usepip:pip install django-organizationsCheck theRelease History tabon
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 installBy default you will need to installdjango-extensionsor comparable libraries
if you plan on adding Django Organizations as an installed app to your Django
project. See below on configuring.ConfiguringMake sure you havedjango.contrib.authinstalled, and add theorganizationsapplication to yourINSTALLED_APPSlist: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:fromorganizations.backendsimportinvitation_backendurlpatterns=[...url(r'^accounts/',include('organizations.urls')),url(r'^invitations/',include(invitation_backend().get_urls())),]Auto slug fieldThe 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 anORGS_TIMESTAMPED_MODELpath. This
is now ignored and the functionality satisfied by a vendored solution. A
warning will be given but thisshould nothave any effect on your code.django-extensionsDjango AutoSlugdjango-sluggerRegistration & invitation backendsYou can specify a different invitation backend in your project settings, and
theinvitation_backendfunction will provide the URLs defined by that
backend:INVITATION_BACKEND='myapp.backends.MyInvitationBackend'Usage OverviewFor 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:OrganizationThe group object. This is what you would associate your own
app’s functionality with, e.g. subscriptions, repositories, projects, etc.OrganizationUserA customthroughmodel for the ManyToMany relationship
between theOrganizationmodel and theUsermodel. It stores additional
information about the user specific to the organization and provides a
convenient link for organization ownership.OrganizationOwnerThe user with rights over the life and death of the
organization. This is a one to one relationship with theOrganizationUsermodel. This allowsUserobjects to own multiple organizations and makes it
easy to enforce ownership from within the organization’s membership.The underlying organizations API is simple:>>>fromorganizations.utilsimportcreate_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:ChrisCornell>>>>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:TomMorello>Custom modelsDjango-organizations can act as a base library (not installed in your project)
and used to create unique organization model sets using custom tables. See theCooking with Django Organizationssection in the documentation for advice on proceeding.LicenseAnyone is free to use or modify this software under the terms of the BSD
license.SponsorsMusteris building precision advocacy software to impact policy through grassroots action.