diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..7a42722 --- /dev/null +++ b/.env.example @@ -0,0 +1,28 @@ +################## +## DJANGO +################## +SECRET_KEY= +DEBUG= +ALLOWED_HOSTS=localhost,127.0.0.1 + + +################## +## POSTGRESQL +################## +POSTGRES_DB= +POSTGRES_USER= +POSTGRES_PASSWORD= +POSTGRES_HOST= +POSTGRES_PORT= + + +################## +## RUNNING PORT +################## +PORT= + + +################## +## RUNNING COMMAND +################## +COMMAND=sh ./resources/scripts/entrypoint.sh \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..6a9068e --- /dev/null +++ b/README.md @@ -0,0 +1,8 @@ +# Qurilish Boshqaruv Backend Saas (Software as a Service) + +## Loyihani Run qilish ketma-ketligi +``` bash +cp .env.example .env # .env fileda kerakli maydonlarni toldirish kerak +``` +``` bash +docker-compose up --build -d \ No newline at end of file diff --git a/apps/accounts/admin.py b/apps/accounts/admin.py deleted file mode 100644 index 8c38f3f..0000000 --- a/apps/accounts/admin.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.contrib import admin - -# Register your models here. diff --git a/apps/accounts/apps.py b/apps/accounts/apps.py deleted file mode 100644 index 3e3c765..0000000 --- a/apps/accounts/apps.py +++ /dev/null @@ -1,6 +0,0 @@ -from django.apps import AppConfig - - -class AccountsConfig(AppConfig): - default_auto_field = 'django.db.models.BigAutoField' - name = 'accounts' diff --git a/apps/accounts/models.py b/apps/accounts/models.py deleted file mode 100644 index 71a8362..0000000 --- a/apps/accounts/models.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.db import models - -# Create your models here. diff --git a/apps/accounts/tests.py b/apps/accounts/tests.py deleted file mode 100644 index 7ce503c..0000000 --- a/apps/accounts/tests.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.test import TestCase - -# Create your tests here. diff --git a/apps/accounts/views.py b/apps/accounts/views.py deleted file mode 100644 index 91ea44a..0000000 --- a/apps/accounts/views.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.shortcuts import render - -# Create your views here. diff --git a/apps/counterparty/admin.py b/apps/counterparty/admin.py deleted file mode 100644 index 8c38f3f..0000000 --- a/apps/counterparty/admin.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.contrib import admin - -# Register your models here. diff --git a/apps/counterparty/apps.py b/apps/counterparty/apps.py deleted file mode 100644 index 328eba7..0000000 --- a/apps/counterparty/apps.py +++ /dev/null @@ -1,6 +0,0 @@ -from django.apps import AppConfig - - -class CounterpartyConfig(AppConfig): - default_auto_field = 'django.db.models.BigAutoField' - name = 'counterparty' diff --git a/apps/counterparty/models.py b/apps/counterparty/models.py deleted file mode 100644 index 71a8362..0000000 --- a/apps/counterparty/models.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.db import models - -# Create your models here. diff --git a/apps/counterparty/tests.py b/apps/counterparty/tests.py deleted file mode 100644 index 7ce503c..0000000 --- a/apps/counterparty/tests.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.test import TestCase - -# Create your tests here. diff --git a/apps/counterparty/views.py b/apps/counterparty/views.py deleted file mode 100644 index 91ea44a..0000000 --- a/apps/counterparty/views.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.shortcuts import render - -# Create your views here. diff --git a/apps/finance/admin.py b/apps/finance/admin.py deleted file mode 100644 index 8c38f3f..0000000 --- a/apps/finance/admin.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.contrib import admin - -# Register your models here. diff --git a/apps/finance/apps.py b/apps/finance/apps.py deleted file mode 100644 index 53023d8..0000000 --- a/apps/finance/apps.py +++ /dev/null @@ -1,6 +0,0 @@ -from django.apps import AppConfig - - -class FinanceConfig(AppConfig): - default_auto_field = 'django.db.models.BigAutoField' - name = 'finance' diff --git a/apps/finance/models.py b/apps/finance/models.py deleted file mode 100644 index 71a8362..0000000 --- a/apps/finance/models.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.db import models - -# Create your models here. diff --git a/apps/finance/tests.py b/apps/finance/tests.py deleted file mode 100644 index 7ce503c..0000000 --- a/apps/finance/tests.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.test import TestCase - -# Create your tests here. diff --git a/apps/finance/views.py b/apps/finance/views.py deleted file mode 100644 index 91ea44a..0000000 --- a/apps/finance/views.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.shortcuts import render - -# Create your views here. diff --git a/apps/orders/admin.py b/apps/orders/admin.py deleted file mode 100644 index 8c38f3f..0000000 --- a/apps/orders/admin.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.contrib import admin - -# Register your models here. diff --git a/apps/orders/apps.py b/apps/orders/apps.py deleted file mode 100644 index 8ae0375..0000000 --- a/apps/orders/apps.py +++ /dev/null @@ -1,6 +0,0 @@ -from django.apps import AppConfig - - -class OrdersConfig(AppConfig): - default_auto_field = 'django.db.models.BigAutoField' - name = 'orders' diff --git a/apps/orders/migrations/__init__.py b/apps/orders/migrations/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/apps/orders/models.py b/apps/orders/models.py deleted file mode 100644 index 71a8362..0000000 --- a/apps/orders/models.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.db import models - -# Create your models here. diff --git a/apps/orders/tests.py b/apps/orders/tests.py deleted file mode 100644 index 7ce503c..0000000 --- a/apps/orders/tests.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.test import TestCase - -# Create your tests here. diff --git a/apps/orders/views.py b/apps/orders/views.py deleted file mode 100644 index 91ea44a..0000000 --- a/apps/orders/views.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.shortcuts import render - -# Create your views here. diff --git a/apps/products/__init__.py b/apps/products/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/apps/products/admin.py b/apps/products/admin.py deleted file mode 100644 index 8c38f3f..0000000 --- a/apps/products/admin.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.contrib import admin - -# Register your models here. diff --git a/apps/products/apps.py b/apps/products/apps.py deleted file mode 100644 index 145a2ac..0000000 --- a/apps/products/apps.py +++ /dev/null @@ -1,6 +0,0 @@ -from django.apps import AppConfig - - -class ProductsConfig(AppConfig): - default_auto_field = 'django.db.models.BigAutoField' - name = 'products' diff --git a/apps/products/migrations/__init__.py b/apps/products/migrations/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/apps/products/models.py b/apps/products/models.py deleted file mode 100644 index 71a8362..0000000 --- a/apps/products/models.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.db import models - -# Create your models here. diff --git a/apps/products/tests.py b/apps/products/tests.py deleted file mode 100644 index 7ce503c..0000000 --- a/apps/products/tests.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.test import TestCase - -# Create your tests here. diff --git a/apps/products/views.py b/apps/products/views.py deleted file mode 100644 index 91ea44a..0000000 --- a/apps/products/views.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.shortcuts import render - -# Create your views here. diff --git a/apps/projects/__init__.py b/apps/projects/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/apps/projects/admin.py b/apps/projects/admin.py deleted file mode 100644 index 8c38f3f..0000000 --- a/apps/projects/admin.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.contrib import admin - -# Register your models here. diff --git a/apps/projects/apps.py b/apps/projects/apps.py deleted file mode 100644 index afae498..0000000 --- a/apps/projects/apps.py +++ /dev/null @@ -1,6 +0,0 @@ -from django.apps import AppConfig - - -class ProjectsConfig(AppConfig): - default_auto_field = 'django.db.models.BigAutoField' - name = 'projects' diff --git a/apps/projects/migrations/__init__.py b/apps/projects/migrations/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/apps/projects/models.py b/apps/projects/models.py deleted file mode 100644 index 71a8362..0000000 --- a/apps/projects/models.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.db import models - -# Create your models here. diff --git a/apps/projects/tests.py b/apps/projects/tests.py deleted file mode 100644 index 7ce503c..0000000 --- a/apps/projects/tests.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.test import TestCase - -# Create your tests here. diff --git a/apps/projects/views.py b/apps/projects/views.py deleted file mode 100644 index 91ea44a..0000000 --- a/apps/projects/views.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.shortcuts import render - -# Create your views here. diff --git a/apps/shared/__init__.py b/apps/shared/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/apps/shared/admin.py b/apps/shared/admin.py deleted file mode 100644 index 8c38f3f..0000000 --- a/apps/shared/admin.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.contrib import admin - -# Register your models here. diff --git a/apps/shared/migrations/__init__.py b/apps/shared/migrations/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/apps/shared/models.py b/apps/shared/models.py deleted file mode 100644 index 71a8362..0000000 --- a/apps/shared/models.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.db import models - -# Create your models here. diff --git a/apps/shared/tests.py b/apps/shared/tests.py deleted file mode 100644 index 7ce503c..0000000 --- a/apps/shared/tests.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.test import TestCase - -# Create your tests here. diff --git a/apps/shared/views.py b/apps/shared/views.py deleted file mode 100644 index 91ea44a..0000000 --- a/apps/shared/views.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.shortcuts import render - -# Create your views here. diff --git a/apps/warehouse/__init__.py b/apps/warehouse/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/apps/warehouse/admin.py b/apps/warehouse/admin.py deleted file mode 100644 index 8c38f3f..0000000 --- a/apps/warehouse/admin.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.contrib import admin - -# Register your models here. diff --git a/apps/warehouse/apps.py b/apps/warehouse/apps.py deleted file mode 100644 index 06c4968..0000000 --- a/apps/warehouse/apps.py +++ /dev/null @@ -1,6 +0,0 @@ -from django.apps import AppConfig - - -class WarehouseConfig(AppConfig): - default_auto_field = 'django.db.models.BigAutoField' - name = 'warehouse' diff --git a/apps/warehouse/migrations/__init__.py b/apps/warehouse/migrations/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/apps/warehouse/models.py b/apps/warehouse/models.py deleted file mode 100644 index 71a8362..0000000 --- a/apps/warehouse/models.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.db import models - -# Create your models here. diff --git a/apps/warehouse/tests.py b/apps/warehouse/tests.py deleted file mode 100644 index 7ce503c..0000000 --- a/apps/warehouse/tests.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.test import TestCase - -# Create your tests here. diff --git a/apps/warehouse/views.py b/apps/warehouse/views.py deleted file mode 100644 index 91ea44a..0000000 --- a/apps/warehouse/views.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.shortcuts import render - -# Create your views here. diff --git a/config/asgi.py b/config/asgi.py index ed7c431..5b6ed6c 100644 --- a/config/asgi.py +++ b/config/asgi.py @@ -11,6 +11,6 @@ import os from django.core.asgi import get_asgi_application -os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings') +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings.base') application = get_asgi_application() diff --git a/apps/accounts/__init__.py b/config/conf/__init__.py similarity index 100% rename from apps/accounts/__init__.py rename to config/conf/__init__.py diff --git a/config/env.py b/config/env.py new file mode 100644 index 0000000..25bfeb4 --- /dev/null +++ b/config/env.py @@ -0,0 +1,3 @@ +from environ import Env + +env = Env() \ No newline at end of file diff --git a/config/settings.py b/config/settings.py deleted file mode 100644 index b77d45b..0000000 --- a/config/settings.py +++ /dev/null @@ -1,122 +0,0 @@ -""" -Django settings for config project. - -Generated by 'django-admin startproject' using Django 5.2. - -For more information on this file, see -https://docs.djangoproject.com/en/5.2/topics/settings/ - -For the full list of settings and their values, see -https://docs.djangoproject.com/en/5.2/ref/settings/ -""" - -from pathlib import Path - -# Build paths inside the project like this: BASE_DIR / 'subdir'. -BASE_DIR = Path(__file__).resolve().parent.parent - - -# Quick-start development settings - unsuitable for production -# See https://docs.djangoproject.com/en/5.2/howto/deployment/checklist/ - -# SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = 'django-insecure-ne#+mtd4hanhi!j%aov$%4e_*^kp^bs+oqv38!t83f20%w5u5-' - -# SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True - -ALLOWED_HOSTS = [] - - -# Application definition - -INSTALLED_APPS = [ - 'django.contrib.admin', - 'django.contrib.auth', - 'django.contrib.contenttypes', - 'django.contrib.sessions', - 'django.contrib.messages', - 'django.contrib.staticfiles', -] - -MIDDLEWARE = [ - 'django.middleware.security.SecurityMiddleware', - 'django.contrib.sessions.middleware.SessionMiddleware', - 'django.middleware.common.CommonMiddleware', - 'django.middleware.csrf.CsrfViewMiddleware', - 'django.contrib.auth.middleware.AuthenticationMiddleware', - 'django.contrib.messages.middleware.MessageMiddleware', - 'django.middleware.clickjacking.XFrameOptionsMiddleware', -] - -ROOT_URLCONF = 'config.urls' - -TEMPLATES = [ - { - 'BACKEND': 'django.template.backends.django.DjangoTemplates', - 'DIRS': [], - 'APP_DIRS': True, - 'OPTIONS': { - 'context_processors': [ - 'django.template.context_processors.request', - 'django.contrib.auth.context_processors.auth', - 'django.contrib.messages.context_processors.messages', - ], - }, - }, -] - -WSGI_APPLICATION = 'config.wsgi.application' - - -# Database -# https://docs.djangoproject.com/en/5.2/ref/settings/#databases - -DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': BASE_DIR / 'db.sqlite3', - } -} - - -# Password validation -# https://docs.djangoproject.com/en/5.2/ref/settings/#auth-password-validators - -AUTH_PASSWORD_VALIDATORS = [ - { - 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', - }, - { - 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', - }, - { - 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', - }, - { - 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', - }, -] - - -# Internationalization -# https://docs.djangoproject.com/en/5.2/topics/i18n/ - -LANGUAGE_CODE = 'en-us' - -TIME_ZONE = 'UTC' - -USE_I18N = True - -USE_TZ = True - - -# Static files (CSS, JavaScript, Images) -# https://docs.djangoproject.com/en/5.2/howto/static-files/ - -STATIC_URL = 'static/' -STATIC_ROOT = BASE_DIR / 'resources/static' -# Default primary key field type -# https://docs.djangoproject.com/en/5.2/ref/settings/#default-auto-field - -DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' diff --git a/apps/accounts/migrations/__init__.py b/config/settings/__init__.py similarity index 100% rename from apps/accounts/migrations/__init__.py rename to config/settings/__init__.py diff --git a/config/settings/base.py b/config/settings/base.py new file mode 100644 index 0000000..7ddd5b6 --- /dev/null +++ b/config/settings/base.py @@ -0,0 +1,119 @@ +from pathlib import Path + +from config.env import env + +BASE_DIR = Path(__file__).resolve().parent.parent.parent + +env.read_env(BASE_DIR / '.env') + + +SECRET_KEY = env.str('SECRET_KEY') +DEBUG = env.str('DEBUG') +ALLOWED_HOSTS = env.list('ALLOWED_HOSTS') + + +# APPS +SHARED_APPS = [ + 'django_tenants', + 'core.apps.customers', + 'django.contrib.contenttypes', +] + +DJANGO_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', +] + +TENANT_APPS = [ + 'core.apps.shared', +] + +PACKAGES = [] + + +INSTALLED_APPS = SHARED_APPS + DJANGO_APPS + PACKAGES + TENANT_APPS + +# Middlewares +MIDDLEWARE = [ + 'django_tenants.middleware.main.TenantMainMiddleware', + 'django.middleware.security.SecurityMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +] + +ROOT_URLCONF = 'config.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + +WSGI_APPLICATION = 'config.wsgi.application' + + +DATABASES = { + 'default': { + 'ENGINE': 'django_tenants.postgresql_backend', + 'NAME': env.str('POSTGRES_DB'), + 'USER': env.str('POSTGRES_USER'), + 'PASSWORD': env.str('POSTGRES_PASSWORD'), + 'HOST': env.str('POSTGRES_HOST'), + 'PORT': env.str('POSTGRES_PORT'), + } +} + +DATABASE_ROUTERS = ( + 'django_tenants.routers.TenantSyncRouter', +) + + +AUTH_PASSWORD_VALIDATORS = [ + { + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + }, +] + + +LANGUAGE_CODE = 'uz' + +TIME_ZONE = 'Asia/Tashkent' + +USE_I18N = True + +USE_TZ = True + + +# Media and Static files +STATIC_URL = 'static/' +STATIC_ROOT = BASE_DIR / 'resources/static' + +MEDIA_URL = 'media/' +MEDIA_ROOT = BASE_DIR / 'resources/media' + + +DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' + +# Django tenants +TENANT_MODEL = "customers.Client" + +TENANT_DOMAIN_MODEL = "customers.Domain" diff --git a/config/settings/dev.py b/config/settings/dev.py new file mode 100644 index 0000000..773cfc4 --- /dev/null +++ b/config/settings/dev.py @@ -0,0 +1 @@ +from .base import * \ No newline at end of file diff --git a/config/urls.py b/config/urls.py index 35a0802..38aa099 100644 --- a/config/urls.py +++ b/config/urls.py @@ -1,22 +1,13 @@ -""" -URL configuration for config project. - -The `urlpatterns` list routes URLs to views. For more information please see: - https://docs.djangoproject.com/en/5.2/topics/http/urls/ -Examples: -Function views - 1. Add an import: from my_app import views - 2. Add a URL to urlpatterns: path('', views.home, name='home') -Class-based views - 1. Add an import: from other_app.views import Home - 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') -Including another URLconf - 1. Import the include() function: from django.urls import include, path - 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) -""" from django.contrib import admin from django.urls import path +from django.conf import settings +from django.conf.urls.static import static + urlpatterns = [ path('admin/', admin.site.urls), ] + + +urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) +urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) \ No newline at end of file diff --git a/config/wsgi.py b/config/wsgi.py index e2fbd58..c46f145 100644 --- a/config/wsgi.py +++ b/config/wsgi.py @@ -11,6 +11,6 @@ import os from django.core.wsgi import get_wsgi_application -os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings') +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings.base') application = get_wsgi_application() diff --git a/apps/counterparty/__init__.py b/core/apps/customers/__init__.py similarity index 100% rename from apps/counterparty/__init__.py rename to core/apps/customers/__init__.py diff --git a/core/apps/customers/admin/__init__.py b/core/apps/customers/admin/__init__.py new file mode 100644 index 0000000..a6e8c1f --- /dev/null +++ b/core/apps/customers/admin/__init__.py @@ -0,0 +1,2 @@ +from .domain import * +from .client import * \ No newline at end of file diff --git a/core/apps/customers/admin/client.py b/core/apps/customers/admin/client.py new file mode 100644 index 0000000..95da56e --- /dev/null +++ b/core/apps/customers/admin/client.py @@ -0,0 +1,11 @@ +from django.contrib import admin + +from core.apps.customers.models import Client +from core.apps.customers.admin.domain import DomainInline + + +@admin.register(Client) +class ClientAdmin(admin.ModelAdmin): + list_display = ['id', 'name', 'schema_name'] + search_fields = ['name'] + inlines = [DomainInline] \ No newline at end of file diff --git a/core/apps/customers/admin/domain.py b/core/apps/customers/admin/domain.py new file mode 100644 index 0000000..48a3caf --- /dev/null +++ b/core/apps/customers/admin/domain.py @@ -0,0 +1,8 @@ +from django.contrib import admin + +from core.apps.customers.models import Domain + + +class DomainInline(admin.TabularInline): + model = Domain + extra = 0 \ No newline at end of file diff --git a/core/apps/customers/apps.py b/core/apps/customers/apps.py new file mode 100644 index 0000000..5850bf8 --- /dev/null +++ b/core/apps/customers/apps.py @@ -0,0 +1,10 @@ +from django.apps import AppConfig + + +class CustomersConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'core.apps.customers' + + def ready(self): + import core.apps.customers.admin + \ No newline at end of file diff --git a/core/apps/customers/management/commands/createclient.py b/core/apps/customers/management/commands/createclient.py new file mode 100644 index 0000000..74ae294 --- /dev/null +++ b/core/apps/customers/management/commands/createclient.py @@ -0,0 +1,22 @@ +from django.core.management import BaseCommand + +from core.apps.customers.models import Client, Domain + +class Command(BaseCommand): + def handle(self, *args, **options): + client_name = input('Mijoz nomini kiriting: ') + schema_name = input('Schema nomini kiriting: ').lower() + domain = input('Domain kiriting: ').lower() + + client, created = Client.objects.get_or_create( + name=client_name, + schema_name=schema_name, + ) + Domain.objects.get_or_create( + domain=domain, + tenant=client, + is_primary=True + ) + + self.stdout("Mijoz qo'shildi") + \ No newline at end of file diff --git a/core/apps/customers/migrations/0001_initial.py b/core/apps/customers/migrations/0001_initial.py new file mode 100644 index 0000000..d28f3f4 --- /dev/null +++ b/core/apps/customers/migrations/0001_initial.py @@ -0,0 +1,42 @@ +# Generated by Django 5.2 on 2025-11-19 10:53 + +import django.db.models.deletion +import django_tenants.postgresql_backend.base +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Client', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('schema_name', models.CharField(db_index=True, max_length=63, unique=True, validators=[django_tenants.postgresql_backend.base._check_schema_name])), + ('name', models.CharField(max_length=100)), + ('paid_until', models.DateField()), + ('on_trial', models.BooleanField()), + ('created_at', models.DateField(auto_now_add=True)), + ], + options={ + 'abstract': False, + }, + ), + migrations.CreateModel( + name='Domain', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('domain', models.CharField(db_index=True, max_length=253, unique=True)), + ('is_primary', models.BooleanField(db_index=True, default=True)), + ('tenant', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='domains', to='customers.client')), + ], + options={ + 'abstract': False, + }, + ), + ] diff --git a/core/apps/customers/migrations/0002_remove_client_on_trial_remove_client_paid_until.py b/core/apps/customers/migrations/0002_remove_client_on_trial_remove_client_paid_until.py new file mode 100644 index 0000000..279dcce --- /dev/null +++ b/core/apps/customers/migrations/0002_remove_client_on_trial_remove_client_paid_until.py @@ -0,0 +1,21 @@ +# Generated by Django 5.2 on 2025-11-19 10:57 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('customers', '0001_initial'), + ] + + operations = [ + migrations.RemoveField( + model_name='client', + name='on_trial', + ), + migrations.RemoveField( + model_name='client', + name='paid_until', + ), + ] diff --git a/apps/counterparty/migrations/__init__.py b/core/apps/customers/migrations/__init__.py similarity index 100% rename from apps/counterparty/migrations/__init__.py rename to core/apps/customers/migrations/__init__.py diff --git a/core/apps/customers/models/__init__.py b/core/apps/customers/models/__init__.py new file mode 100644 index 0000000..e56fc89 --- /dev/null +++ b/core/apps/customers/models/__init__.py @@ -0,0 +1,2 @@ +from .client import * +from .domain import * \ No newline at end of file diff --git a/core/apps/customers/models/client.py b/core/apps/customers/models/client.py new file mode 100644 index 0000000..52971dc --- /dev/null +++ b/core/apps/customers/models/client.py @@ -0,0 +1,10 @@ +from django.db import models + +from django_tenants.models import TenantMixin + + +class Client(TenantMixin): + name = models.CharField(max_length=100) + created_at = models.DateField(auto_now_add=True) + + auto_create_schema = True \ No newline at end of file diff --git a/core/apps/customers/models/domain.py b/core/apps/customers/models/domain.py new file mode 100644 index 0000000..c8aeee2 --- /dev/null +++ b/core/apps/customers/models/domain.py @@ -0,0 +1,7 @@ +from django.db import models + +from django_tenants.models import DomainMixin + + +class Domain(DomainMixin): + pass \ No newline at end of file diff --git a/core/apps/customers/urls.py b/core/apps/customers/urls.py new file mode 100644 index 0000000..2787512 --- /dev/null +++ b/core/apps/customers/urls.py @@ -0,0 +1,6 @@ +from django.urls import path + + +urlpatterns = [ + +] \ No newline at end of file diff --git a/apps/finance/__init__.py b/core/apps/shared/__init__.py similarity index 100% rename from apps/finance/__init__.py rename to core/apps/shared/__init__.py diff --git a/apps/shared/apps.py b/core/apps/shared/apps.py similarity index 80% rename from apps/shared/apps.py rename to core/apps/shared/apps.py index 87efe00..ca9e94d 100644 --- a/apps/shared/apps.py +++ b/core/apps/shared/apps.py @@ -3,4 +3,4 @@ from django.apps import AppConfig class SharedConfig(AppConfig): default_auto_field = 'django.db.models.BigAutoField' - name = 'shared' + name = 'core.apps.shared' diff --git a/apps/finance/migrations/__init__.py b/core/apps/shared/migrations/__init__.py similarity index 100% rename from apps/finance/migrations/__init__.py rename to core/apps/shared/migrations/__init__.py diff --git a/core/apps/shared/models/__init__.py b/core/apps/shared/models/__init__.py new file mode 100644 index 0000000..773cfc4 --- /dev/null +++ b/core/apps/shared/models/__init__.py @@ -0,0 +1 @@ +from .base import * \ No newline at end of file diff --git a/core/apps/shared/models/base.py b/core/apps/shared/models/base.py new file mode 100644 index 0000000..342a4e2 --- /dev/null +++ b/core/apps/shared/models/base.py @@ -0,0 +1,9 @@ +from django.db import models + + +class BaseModel(models.Model): + created_at = models.DateTimeField(auto_now_add=True) + updated_at = models.DateTimeField(auto_now=True) + + class Meta: + abstract = True \ No newline at end of file diff --git a/apps/orders/__init__.py b/core/apps/shared/urls.py similarity index 100% rename from apps/orders/__init__.py rename to core/apps/shared/urls.py diff --git a/docker-compose.yaml b/docker-compose.yaml index 9cbba19..69928e6 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,9 +1,9 @@ services: nginx: networks: - - uyqur + - qurish_boshqaruv ports: - - ${PORT:-8001}:80 + - ${PORT:-8000}:80 volumes: - ./resources/layout/nginx.conf:/etc/nginx/nginx.conf - ./resources/:/usr/share/nginx/html/resources/ @@ -16,7 +16,7 @@ services: web: networks: - - uyqur + - qurish_boshqaruv build: context: . dockerfile: ./docker/Dockerfile.web @@ -27,13 +27,12 @@ services: - './:/code' depends_on: - db - - redis restart: always db: image: postgres:17 networks: - - uyqur + - qurish_boshqaruv environment: POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} POSTGRES_USER: ${POSTGRES_USER} @@ -42,33 +41,10 @@ services: - pg_data:/var/lib/postgresql/data restart: always - redis: - networks: - - uyqur - image: redis - restart: always - - # celery: - # build: - # context: . - # dockerfile: ./docker/Dockerfile.web - # command: celery -A config worker --loglevel=info - # volumes: - # - "./:/code" - # depends_on: - # - redis - # - web - # networks: - # - uyqur - # environment: - # - CELERY_BROKER_URL=${CELERY_BROKER_URL:-redis://redis:6379/0} - # - CELERY_RESULT_BACKEND=${CELERY_RESULT_BACKEND:-redis://redis:6379/0} - # restart: always - volumes: pg_data: null networks: - uyqur: + qurish_boshqaruv: driver: bridge \ No newline at end of file diff --git a/manage.py b/manage.py index 8e7ac79..6361598 100755 --- a/manage.py +++ b/manage.py @@ -6,7 +6,7 @@ import sys def main(): """Run administrative tasks.""" - os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings') + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings.base') try: from django.core.management import execute_from_command_line except ImportError as exc: diff --git a/requirements.txt b/requirements.txt index 54c5cde..a5ad1f5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,11 @@ +asgiref==3.10.0 +click==8.3.1 Django==5.2 +django-environ==0.12.0 +django-tenants==3.9.0 gunicorn==23.0.0 +h11==0.16.0 +packaging==25.0 +psycopg2-binary==2.9.11 +sqlparse==0.5.3 uvicorn==0.38.0 -celery \ No newline at end of file diff --git a/resources/scripts/entrypoint.sh b/resources/scripts/entrypoint.sh index 46e4391..fcc25c6 100644 --- a/resources/scripts/entrypoint.sh +++ b/resources/scripts/entrypoint.sh @@ -2,6 +2,6 @@ python3 manage.py collectstatic --noinput python3 manage.py migrate --noinput -uvicorn config.asgi:application --host 0.0.0.0 --port 8000 --reload --reload-dir apps --reload-dir config +uvicorn config.asgi:application --host 0.0.0.0 --port 8000 --reload --reload-dir core --reload-dir config exit $?