# Django Settings Configuration Plan ## Overview This document outlines the Django settings configuration for the manufacturing application, including database setup, internationalization, static files, and other important configurations. ## Key Settings Implementation ### 1. Basic Configuration ```python # settings.py # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = 'your-secret-key-here' # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True ALLOWED_HOSTS = ['localhost', '127.0.0.1'] # Application definition INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', # Third-party apps 'bootstrap5', 'crispy_forms', 'crispy_bootstrap5', # Local apps 'accounts', 'inventory', 'purchasing', 'sales', 'manufacturing', 'database_management', 'reports', 'dashboard', ] MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', 'whitenoise.middleware.WhiteNoiseMiddleware', # For static files 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.locale.LocaleMiddleware', # For internationalization 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', ] ROOT_URLCONF = 'manufacturing_app.urls' TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [BASE_DIR / 'templates'], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ 'django.template.context_processors.debug', 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', ], }, }, ] WSGI_APPLICATION = 'manufacturing_app.wsgi.application' ``` ### 2. Database Configuration ```python # Database # SQLite for development, PostgreSQL for production import os from decouple import config if config('DATABASE_URL', default=None): # Production - PostgreSQL DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql', 'NAME': config('DB_NAME'), 'USER': config('DB_USER'), 'PASSWORD': config('DB_PASSWORD'), 'HOST': config('DB_HOST'), 'PORT': config('DB_PORT', default='5432'), } } else: # Development - SQLite DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': BASE_DIR / 'db.sqlite3', } } ``` ### 3. Internationalization and Localization ```python # Internationalization LANGUAGE_CODE = 'id' # Indonesian language code USE_I18N = True TIME_ZONE = 'Asia/Jakarta' USE_TZ = True # Additional localization settings LANGUAGES = [ ('id', 'Indonesian'), ('en', 'English'), ] LOCALE_PATHS = [ BASE_DIR / 'locale', ] # Format localization USE_L10N = True USE_THOUSAND_SEPARATOR = True ``` ### 4. Static and Media Files ```python # Static files (CSS, JavaScript, Images) STATIC_URL = '/static/' STATIC_ROOT = BASE_DIR / 'staticfiles' STATICFILES_DIRS = [ BASE_DIR / 'static', ] # Media files (User uploads) MEDIA_URL = '/media/' MEDIA_ROOT = BASE_DIR / 'media' # Static files storage for production STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage' ``` ### 5. Authentication and Security ```python # Authentication AUTH_USER_MODEL = 'accounts.User' # Custom user model LOGIN_URL = '/accounts/login/' LOGIN_REDIRECT_URL = '/' LOGOUT_REDIRECT_URL = '/' # Password validation 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', }, ] # Security settings SECURE_BROWSER_XSS_FILTER = True SECURE_CONTENT_TYPE_NOSNIFF = True X_FRAME_OPTIONS = 'DENY' ``` ### 6. Third-party App Settings ```python # Bootstrap 5 settings BOOTSTRAP5 = { 'css_url': { 'url': 'https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css', }, 'javascript_url': { 'url': 'https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js', }, 'theme_url': None, 'javascript_in_head': False, 'include_jquery': False, 'use_i18n': True, } # Crispy forms settings CRISPY_ALLOWED_TEMPLATE_PACKS = "bootstrap5" CRISPY_TEMPLATE_PACK = "bootstrap5" # Session settings SESSION_COOKIE_AGE = 3600 # 1 hour SESSION_SAVE_EVERY_REQUEST = True ``` ### 7. Email Configuration (Optional) ```python # Email settings EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' EMAIL_HOST = config('EMAIL_HOST', default='localhost') EMAIL_PORT = config('EMAIL_PORT', default=587, cast=int) EMAIL_USE_TLS = config('EMAIL_USE_TLS', default=True, cast=bool) EMAIL_HOST_USER = config('EMAIL_HOST_USER', default='') EMAIL_HOST_PASSWORD = config('EMAIL_HOST_PASSWORD', default='') DEFAULT_FROM_EMAIL = 'noreply@manufacturing-app.com' ``` ### 8. Logging Configuration ```python # Logging LOGGING = { 'version': 1, 'disable_existing_loggers': False, 'handlers': { 'file': { 'level': 'DEBUG', 'class': 'logging.FileHandler', 'filename': BASE_DIR / 'logs/django.log', }, 'console': { 'level': 'DEBUG', 'class': 'logging.StreamHandler', }, }, 'root': { 'handlers': ['file', 'console'], 'level': 'DEBUG', }, 'loggers': { 'django': { 'handlers': ['file', 'console'], 'level': 'DEBUG', 'propagate': False, }, }, } ``` ### 9. Custom App Settings ```python # Custom application settings # Reporting settings REPORTS_PER_PAGE = 20 EXCEL_EXPORT_LIMIT = 10000 # Inventory settings DEFAULT_REORDER_LEVEL = 10 STOCK_ALERT_THRESHOLD = 5 # Manufacturing settings DEFAULT_MO_STATUS = 'draft' PRODUCTION_SCHEDULING_DAYS = 7 ``` ## Environment-based Configuration For different environments (development, staging, production), we'll use environment variables: ### Development (.env file) ``` DEBUG=True SECRET_KEY=your-development-secret-key DATABASE_URL= ALLOWED_HOSTS=localhost,127.0.0.1 ``` ### Production ``` DEBUG=False SECRET_KEY=your-production-secret-key DATABASE_URL=postgres://user:password@host:port/dbname ALLOWED_HOSTS=yourdomain.com,www.yourdomain.com ``` ## Implementation Notes 1. **Security**: The secret key should be different for development and production environments 2. **Database**: SQLite is used for development, PostgreSQL for production 3. **Static Files**: WhiteNoise is used for serving static files in production 4. **Internationalization**: Indonesian is set as the primary language with English as fallback 5. **Timezone**: Asia/Jakarta is configured as the default timezone 6. **Bootstrap**: Bootstrap 5 is integrated for the UI framework 7. **Custom User Model**: A custom user model is used for extended user functionality This configuration provides a solid foundation for the manufacturing application with proper security, internationalization, and scalability considerations.