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
and GARPIX_COMPANY_ROLE_MODEL
to settings.py
:
# settings.py
GARPIX_COMPANY_MODEL = 'app.Company'
GARPIX_COMPANY_ROLE_MODEL = 'app.UserCompanyRole'
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
to add custom fields to user
field of /company/{pk}/user/
endpoints:
# settings.py
GARPIX_COMPANY_USER_SERIALIZER = 'app.serializers.UserSerializer'
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, UserCompany
class Company(AbstractCompany):
@classmethod
def check_user_companies_limit(cls, user):
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
Hashes for garpix_company-1.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aced1bf0d04500d4a320c76039b938bf9fa7560e227b34d9c7c231bb4e2eaf4f |
|
MD5 | f73e83ff6e099786538747ee0dc0cc5c |
|
BLAKE2b-256 | cc54bf102ef7dbce76bef210c40185cd44f5298a378dca2ae012ea21d87a6662 |