Merge pull request #1 from Behruz-s-organization/dev

dev branchdan main branch uchun birinchi merge
This commit is contained in:
xolikberdiyev
2025-11-19 16:20:00 +05:00
committed by GitHub
82 changed files with 335 additions and 311 deletions

28
.env.example Normal file
View File

@@ -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

8
README.md Normal file
View File

@@ -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

View File

@@ -1,3 +0,0 @@
from django.contrib import admin
# Register your models here.

View File

@@ -1,6 +0,0 @@
from django.apps import AppConfig
class AccountsConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'accounts'

View File

@@ -1,3 +0,0 @@
from django.db import models
# Create your models here.

View File

@@ -1,3 +0,0 @@
from django.test import TestCase
# Create your tests here.

View File

@@ -1,3 +0,0 @@
from django.shortcuts import render
# Create your views here.

View File

@@ -1,3 +0,0 @@
from django.contrib import admin
# Register your models here.

View File

@@ -1,6 +0,0 @@
from django.apps import AppConfig
class CounterpartyConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'counterparty'

View File

@@ -1,3 +0,0 @@
from django.db import models
# Create your models here.

View File

@@ -1,3 +0,0 @@
from django.test import TestCase
# Create your tests here.

View File

@@ -1,3 +0,0 @@
from django.shortcuts import render
# Create your views here.

View File

@@ -1,3 +0,0 @@
from django.contrib import admin
# Register your models here.

View File

@@ -1,6 +0,0 @@
from django.apps import AppConfig
class FinanceConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'finance'

View File

@@ -1,3 +0,0 @@
from django.db import models
# Create your models here.

View File

@@ -1,3 +0,0 @@
from django.test import TestCase
# Create your tests here.

View File

@@ -1,3 +0,0 @@
from django.shortcuts import render
# Create your views here.

View File

@@ -1,3 +0,0 @@
from django.contrib import admin
# Register your models here.

View File

@@ -1,6 +0,0 @@
from django.apps import AppConfig
class OrdersConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'orders'

View File

@@ -1,3 +0,0 @@
from django.db import models
# Create your models here.

View File

@@ -1,3 +0,0 @@
from django.test import TestCase
# Create your tests here.

View File

@@ -1,3 +0,0 @@
from django.shortcuts import render
# Create your views here.

View File

@@ -1,3 +0,0 @@
from django.contrib import admin
# Register your models here.

View File

@@ -1,6 +0,0 @@
from django.apps import AppConfig
class ProductsConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'products'

View File

@@ -1,3 +0,0 @@
from django.db import models
# Create your models here.

View File

@@ -1,3 +0,0 @@
from django.test import TestCase
# Create your tests here.

View File

@@ -1,3 +0,0 @@
from django.shortcuts import render
# Create your views here.

View File

@@ -1,3 +0,0 @@
from django.contrib import admin
# Register your models here.

View File

@@ -1,6 +0,0 @@
from django.apps import AppConfig
class ProjectsConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'projects'

View File

@@ -1,3 +0,0 @@
from django.db import models
# Create your models here.

View File

@@ -1,3 +0,0 @@
from django.test import TestCase
# Create your tests here.

View File

@@ -1,3 +0,0 @@
from django.shortcuts import render
# Create your views here.

View File

@@ -1,3 +0,0 @@
from django.contrib import admin
# Register your models here.

View File

@@ -1,3 +0,0 @@
from django.db import models
# Create your models here.

View File

@@ -1,3 +0,0 @@
from django.test import TestCase
# Create your tests here.

View File

@@ -1,3 +0,0 @@
from django.shortcuts import render
# Create your views here.

View File

@@ -1,3 +0,0 @@
from django.contrib import admin
# Register your models here.

View File

@@ -1,6 +0,0 @@
from django.apps import AppConfig
class WarehouseConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'warehouse'

View File

@@ -1,3 +0,0 @@
from django.db import models
# Create your models here.

View File

@@ -1,3 +0,0 @@
from django.test import TestCase
# Create your tests here.

View File

@@ -1,3 +0,0 @@
from django.shortcuts import render
# Create your views here.

View File

@@ -11,6 +11,6 @@ import os
from django.core.asgi import get_asgi_application 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() application = get_asgi_application()

3
config/env.py Normal file
View File

@@ -0,0 +1,3 @@
from environ import Env
env = Env()

View File

@@ -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'

119
config/settings/base.py Normal file
View File

@@ -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"

1
config/settings/dev.py Normal file
View File

@@ -0,0 +1 @@
from .base import *

View File

@@ -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.contrib import admin
from django.urls import path from django.urls import path
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [ urlpatterns = [
path('admin/', admin.site.urls), 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)

View File

@@ -11,6 +11,6 @@ import os
from django.core.wsgi import get_wsgi_application 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() application = get_wsgi_application()

View File

@@ -0,0 +1,2 @@
from .domain import *
from .client import *

View File

@@ -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]

View File

@@ -0,0 +1,8 @@
from django.contrib import admin
from core.apps.customers.models import Domain
class DomainInline(admin.TabularInline):
model = Domain
extra = 0

View File

@@ -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

View File

@@ -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")

View File

@@ -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,
},
),
]

View File

@@ -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',
),
]

View File

@@ -0,0 +1,2 @@
from .client import *
from .domain import *

View File

@@ -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

View File

@@ -0,0 +1,7 @@
from django.db import models
from django_tenants.models import DomainMixin
class Domain(DomainMixin):
pass

View File

@@ -0,0 +1,6 @@
from django.urls import path
urlpatterns = [
]

View File

@@ -3,4 +3,4 @@ from django.apps import AppConfig
class SharedConfig(AppConfig): class SharedConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField' default_auto_field = 'django.db.models.BigAutoField'
name = 'shared' name = 'core.apps.shared'

View File

@@ -0,0 +1 @@
from .base import *

View File

@@ -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

View File

@@ -1,9 +1,9 @@
services: services:
nginx: nginx:
networks: networks:
- uyqur - qurish_boshqaruv
ports: ports:
- ${PORT:-8001}:80 - ${PORT:-8000}:80
volumes: volumes:
- ./resources/layout/nginx.conf:/etc/nginx/nginx.conf - ./resources/layout/nginx.conf:/etc/nginx/nginx.conf
- ./resources/:/usr/share/nginx/html/resources/ - ./resources/:/usr/share/nginx/html/resources/
@@ -16,7 +16,7 @@ services:
web: web:
networks: networks:
- uyqur - qurish_boshqaruv
build: build:
context: . context: .
dockerfile: ./docker/Dockerfile.web dockerfile: ./docker/Dockerfile.web
@@ -27,13 +27,12 @@ services:
- './:/code' - './:/code'
depends_on: depends_on:
- db - db
- redis
restart: always restart: always
db: db:
image: postgres:17 image: postgres:17
networks: networks:
- uyqur - qurish_boshqaruv
environment: environment:
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_USER: ${POSTGRES_USER} POSTGRES_USER: ${POSTGRES_USER}
@@ -42,33 +41,10 @@ services:
- pg_data:/var/lib/postgresql/data - pg_data:/var/lib/postgresql/data
restart: always 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: volumes:
pg_data: null pg_data: null
networks: networks:
uyqur: qurish_boshqaruv:
driver: bridge driver: bridge

View File

@@ -6,7 +6,7 @@ import sys
def main(): def main():
"""Run administrative tasks.""" """Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings') os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings.base')
try: try:
from django.core.management import execute_from_command_line from django.core.management import execute_from_command_line
except ImportError as exc: except ImportError as exc:

View File

@@ -1,4 +1,11 @@
asgiref==3.10.0
click==8.3.1
Django==5.2 Django==5.2
django-environ==0.12.0
django-tenants==3.9.0
gunicorn==23.0.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 uvicorn==0.38.0
celery

View File

@@ -2,6 +2,6 @@
python3 manage.py collectstatic --noinput python3 manage.py collectstatic --noinput
python3 manage.py migrate --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 $? exit $?