No project description provided
Project description
Garpix Company
Company module for Django/DRF projects.
Quickstart
Install with pip:
pip install garpix_company
Add the garpix_company
to your INSTALLED_APPS
:
# settings.py
# ...
INSTALLED_APPS = [
# ...
'garpix_company',
]
and to migration modules:
# settings.py
# ...
MIGRATION_MODULES = {
'garpix_company': 'app.migrations.garpix_company',
}
Add to urls.py
:
# ...
urlpatterns = [
# ...
# garpix_company
path('', include(('garpix_company.urls', 'garpix_company'), namespace='garpix_company')),
]
Add Company model to your project using abstract AbstractCompany
from the model:
from garpix_company.models import AbstractCompany
class Company(AbstractCompany):
pass
Add UserCompanyRole model to your project using abstract AbstractUserCompanyRole
from the model:
from garpix_company.models import AbstractUserCompanyRole
class UserCompanyRole(AbstractUserCompanyRole):
pass
Add GARPIX_COMPANY_MODEL
, GARPIX_USER_COMPANY_MODEL
and GARPIX_COMPANY_ROLE_MODEL
to settings.py
:
# settings.py
GARPIX_COMPANY_MODEL = 'app.Company'
GARPIX_COMPANY_ROLE_MODEL = 'app.UserCompanyRole'
GARPIX_USER_COMPANY_MODEL = 'garpix_company.UserCompany'
Use CompanyAdmin
as base in your admin panel:
from django.contrib import admin
from app.models import Company
from garpix_company.admin import CompanyAdmin
@admin.register(Company)
class CompanyAdmin(CompanyAdmin):
pass
Invite and create user
You can add fields to company_invite/create_and_invite
endpoint.
To do it override CreateAndInviteToCompanySerializer
by adding field and add it to settings
:
# settings.py
GARPIX_COMPANY_CREATE_AND_INVITE_SERIALIZER = 'app.serializers.CustomInviteCompanySerializer'
# app.serializers.py
from rest_framework import serializers
from garpix_company.serializers import CreateAndInviteToCompanySerializer
class CustomInviteCompanySerializer(CreateAndInviteToCompanySerializer):
username = serializers.CharField(write_only=True)
class Meta(CreateAndInviteToCompanySerializer.Meta):
fields = CreateAndInviteToCompanySerializer.Meta.fields + ('username',)
You also can override UserSerializer
and CompanyRoleSerializer
to add custom fields to user
and role
fields of /company/{pk}/user/
endpoints:
# settings.py
GARPIX_COMPANY_USER_SERIALIZER = 'app.serializers.UserSerializer'
GARPIX_COMPANY_ROLE_SERIALIZER = 'app.serializers.CompanyRoleSerializer'
You can also set GARPIX_COMPANY_INVITE_NOT_USERS
setting to True (False is default) to allow to invite not registered users
Companies count limit
If you need to add some limitations on companies count the user can be a part of, you can override check_user_companies_limit
class method of Company
class:
from garpix_company.models import AbstractCompany, get_user_company_model
class Company(AbstractCompany):
@classmethod
def check_user_companies_limit(cls, user):
UserCompany = get_user_company_model()
return UserCompany.objects.filter(user=user).count() < 1
See garpix_company/tests/test_company.py
for examples.
Changelog
Смотри CHANGELOG.md.
Contributing
Смотри CONTRIBUTING.md.
License
Developed by Garpix / https://garpix.com
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file garpix_company-2.9.0rc10.tar.gz
.
File metadata
- Download URL: garpix_company-2.9.0rc10.tar.gz
- Upload date:
- Size: 30.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/7.0.2 pkginfo/1.10.0 requests/2.31.0 requests-toolbelt/1.0.0 tqdm/4.66.2 CPython/3.8.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f360d583ddc3ad4986f51fa1f63b5ead43740e4e9caced4d07842529fe5de3af |
|
MD5 | 3454e397c27b39af71a1d00f15f2513c |
|
BLAKE2b-256 | 487202f06102d1752d11fd898eb0a320758144f30480ff5c3cbdc350973eb2b2 |
File details
Details for the file garpix_company-2.9.0rc10-py3-none-any.whl
.
File metadata
- Download URL: garpix_company-2.9.0rc10-py3-none-any.whl
- Upload date:
- Size: 50.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/7.0.2 pkginfo/1.10.0 requests/2.31.0 requests-toolbelt/1.0.0 tqdm/4.66.2 CPython/3.8.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 121e9bd0513c789d3149c518faced52e97884dc57b3fb57b651005ddd96fe12b |
|
MD5 | 2ee3f15bfb6c8004d40dbf43a368449d |
|
BLAKE2b-256 | 330044ae7e6d15b97d6cfab84132d78a883213f518dc6accea90a577232f4d76 |