# GLOBAL SETTINGS - DJANGO ADMIN ACCESS GUIDE

**Last Updated**: December 20, 2025  
**Status**: ✅ READY TO USE

---

## WHERE TO FIND GLOBAL SETTINGS IN DJANGO ADMIN

### 1. Global AI Integration Settings (API Keys)

**URL**: http://your-domain.com/admin/system/globalintegrationsettings/

**What It Controls**:
- OpenAI API key (for text generation)
- OpenAI model selection (gpt-4, gpt-3.5-turbo, etc.)
- OpenAI temperature and max_tokens
- DALL-E API key (for image generation)
- DALL-E model, size, quality, style
- Anthropic API key (for Claude)
- Anthropic model selection
- Runware API key (for advanced image generation)

**Important**:
- This is a SINGLETON - only ONE record exists (ID=1)
- Changes here affect ALL accounts by default
- Enterprise accounts can override with their own keys

**How to Configure**:
1. Login to Django Admin as superuser
2. Navigate to: System → Global integration settings
3. Click on the single "Global Integration Settings" entry
4. Fill in your platform-wide API keys
5. Set default models and parameters
6. Save

---

### 2. Account Integration Overrides (Per-Account API Keys)

**URL**: http://your-domain.com/admin/system/accountintegrationoverride/

**What It Controls**:
- Per-account API key overrides for enterprise customers
- Each account can optionally use their own keys
- Falls back to global if not configured

**Fields**:
- Account (select which account)
- use_own_keys (checkbox - if unchecked, uses global)
- Same API key fields as global (all optional)

**How to Configure**:
1. Navigate to: System → Account integration overrides
2. Click "Add account integration override"
3. Select the account
4. Check "Use own keys"
5. Fill in their API keys
6. Save

**How It Works**:
- If account has override with use_own_keys=True → uses their keys
- If account has NO override OR use_own_keys=False → uses global keys
- Account can be deleted/disabled to revert to global

---

### 3. Global AI Prompts (Prompt Templates Library)

**URL**: http://your-domain.com/admin/system/globalaiprompt/

**What It Controls**:
- Platform-wide default AI prompt templates
- Used for clustering, content generation, ideas, etc.
- All accounts can use these prompts
- Accounts can customize their own versions

**Fields**:
- Prompt type (clustering, ideas, content_generation, etc.)
- Prompt value (the actual prompt template)
- Description (what this prompt does)
- Variables (list of available variables like {keyword}, {industry})
- Version (for tracking changes)
- Is active (enable/disable)

**How to Configure**:
1. Navigate to: System → Global ai prompts
2. Click "Add global ai prompt"
3. Select prompt type (or create new)
4. Write your prompt template
5. List variables it uses
6. Mark as active
7. Save

**Account Usage**:
- Accounts automatically use global prompts
- Accounts can create customized versions in their own AIPrompt records
- Accounts can reset to global anytime

---

### 4. Global Author Profiles (Persona Templates Library)

**URL**: http://your-domain.com/admin/system/globalauthorprofile/

**What It Controls**:
- Platform-wide author persona templates
- Tone of voice configurations
- Writing style templates
- Accounts can clone and customize

**Fields**:
- Name (e.g., "SaaS B2B Professional")
- Description (what this persona is for)
- Tone (professional, casual, technical, etc.)
- Language (en, es, fr, etc.)
- Structure template (JSON config for content structure)
- Category (saas, ecommerce, blog, technical, creative)
- Is active (enable/disable)

**How to Configure**:
1. Navigate to: System → Global author profiles
2. Click "Add global author profile"
3. Create a persona template
4. Set tone and language
5. Add structure template if needed
6. Assign category
7. Save

**Account Usage**:
- Accounts browse global library
- Accounts clone a template to create their own version
- Cloned version stored in AuthorProfile model with cloned_from reference
- Accounts can customize their clone without affecting global

---

### 5. Global Strategies (Content Strategy Templates)

**URL**: http://your-domain.com/admin/system/globalstrategy/

**What It Controls**:
- Platform-wide content strategy templates
- Section structures for different content types
- Prompt sequences for content generation
- Accounts can clone and customize

**Fields**:
- Name (e.g., "SEO Blog Post Strategy")
- Description (what this strategy achieves)
- Category (blog, product, howto, comparison, etc.)
- Prompt types (which prompts to use)
- Section logic (JSON config for content sections)
- Is active (enable/disable)

**How to Configure**:
1. Navigate to: System → Global strategies
2. Click "Add global strategy"
3. Create a strategy template
4. Define section structure
5. Specify which prompts to use
6. Add section logic JSON
7. Save

**Account Usage**:
- Similar to author profiles
- Accounts clone global templates
- Customize for their needs
- Track origin via cloned_from field

---

## ACCOUNT-SPECIFIC MODELS (Not Global)

These remain account-specific as originally designed:

### AIPrompt (Account-Level)
**URL**: /admin/system/aiprompt/
- Per-account AI prompt customizations
- References global prompts by default
- Can be customized (is_customized=True)
- Can reset to global anytime

### AuthorProfile (Account-Level)
**URL**: /admin/system/authorprofile/
- Per-account author personas
- Can be cloned from global (cloned_from field)
- Can be created from scratch (is_custom=True)

### Strategy (Account-Level)
**URL**: /admin/system/strategy/
- Per-account content strategies
- Can be cloned from global
- Can be created from scratch

### IntegrationSettings (Account-Level) - DEPRECATED
**URL**: /admin/system/integrationsettings/
**Status**: This model is being phased out in favor of Global + Override pattern
**Do Not Use**: Use GlobalIntegrationSettings and AccountIntegrationOverride instead

---

## NAVIGATION IN DJANGO ADMIN

When you login to Django Admin, you'll see:

```
SYSTEM
├── Global Integration Settings (1 entry - singleton)
├── Account Integration Overrides (0+ entries - one per enterprise account)
├── Global AI Prompts (library of prompt templates)
├── Global Author Profiles (library of persona templates)
├── Global Strategies (library of strategy templates)
├── AI Prompts (per-account customizations)
├── Author Profiles (per-account personas)
├── Strategies (per-account strategies)
└── Integration Settings (DEPRECATED - old model)
```

---

## QUICK START CHECKLIST

After deployment, configure in this order:

1. **Set Global API Keys** (/admin/system/globalintegrationsettings/)
   - [ ] OpenAI API key
   - [ ] DALL-E API key
   - [ ] Anthropic API key (optional)
   - [ ] Runware API key (optional)
   - [ ] Set default models and parameters

2. **Create Global Prompt Library** (/admin/system/globalaiprompt/)
   - [ ] Clustering prompt
   - [ ] Content ideas prompt
   - [ ] Content generation prompt
   - [ ] Meta description prompt
   - [ ] Title generation prompt

3. **Create Global Author Profiles** (/admin/system/globalauthorprofile/)
   - [ ] Professional B2B profile
   - [ ] E-commerce profile
   - [ ] Blog/casual profile
   - [ ] Technical profile
   - [ ] Creative profile

4. **Create Global Strategies** (/admin/system/globalstrategy/)
   - [ ] SEO blog post strategy
   - [ ] Product launch strategy
   - [ ] How-to guide strategy
   - [ ] Comparison article strategy

5. **Test with Regular Account**
   - [ ] Create content using global prompts
   - [ ] Verify global API keys work
   - [ ] Test cloning profiles/strategies

6. **Configure Enterprise Account** (if needed)
   - [ ] Create AccountIntegrationOverride
   - [ ] Add their API keys
   - [ ] Enable use_own_keys
   - [ ] Test their custom keys work

---

## TROUBLESHOOTING

**Problem**: Can't see Global Integration Settings in admin

**Solution**: 
1. Check you're logged in as superuser
2. Refresh the page
3. Check URL: /admin/system/globalintegrationsettings/
4. Verify migration applied: `docker exec igny8_backend python manage.py showmigrations system`

---

**Problem**: Global settings not taking effect

**Solution**:
1. Check GlobalIntegrationSettings has values saved
2. Verify is_active=True
3. Check no AccountIntegrationOverride for the account
4. Restart backend: `docker restart igny8_backend`

---

**Problem**: Account override not working

**Solution**:
1. Check use_own_keys checkbox is enabled
2. Verify API keys are filled in
3. Check account selected correctly
4. Test the API keys manually

---

## API ACCESS TO GLOBAL SETTINGS

Code can access global settings:

**Get Global Integration Settings**:
```python
from igny8_core.modules.system.global_settings_models import GlobalIntegrationSettings
settings = GlobalIntegrationSettings.get_instance()
```

**Get Effective Settings for Account** (checks override, falls back to global):
```python
from igny8_core.ai.settings import get_openai_settings
settings = get_openai_settings(account)
```

**Get Global Prompt**:
```python
from igny8_core.modules.system.global_settings_models import GlobalAIPrompt
prompt = GlobalAIPrompt.objects.get(prompt_type='clustering', is_active=True)
```

---

*For complete implementation details, see COMPLETE-IMPLEMENTATION-GUIDE.md*
