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',)
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.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 639d0110b14b529ab498457440c197364d61810c63600e93175c43d84b7aa85c |
|
MD5 | 7e0239c70f4c7b4a3c511631efbe791b |
|
BLAKE2b-256 | 338231adeaa6df6230484c14d94b61d99fbe9503c8686ae4f75eec40b588eeba |