Browse Source

Update Agent admin interface to improve prompt management

- Changed `TabularInline` to `StackedInline` for better layout of `AgentPrompt` entries.
- Adjusted the `AdminTextareaWidget` to enhance user experience with improved styling and sizing.
- Ensured the inline management of prompts remains user-friendly and visually appealing in the admin interface.
master
Mohsen Taba 3 months ago
parent
commit
4c871bd1bc
  1. 53
      apps/agent/admin.py

53
apps/agent/admin.py

@ -2,45 +2,48 @@ from django.contrib import admin
from django.db import models from django.db import models
from django.shortcuts import redirect from django.shortcuts import redirect
from django.urls import reverse from django.urls import reverse
from unfold.admin import ModelAdmin, TabularInline
# 1. Change TabularInline to StackedInline
from unfold.admin import ModelAdmin, TabularInline
from utils.admin import dovoodi_admin_site, project_admin_site from utils.admin import dovoodi_admin_site, project_admin_site
from .models import AgentSettings, AgentPrompt from .models import AgentSettings, AgentPrompt
from unfold.contrib.forms.widgets import WysiwygWidget
class AgentPromptInline(TabularInline):
class AgentPromptInline(TabularInline):
model = AgentPrompt model = AgentPrompt
extra = 0 extra = 0
fields = ('is_active', 'content')
fields = ('is_active', 'content')
formfield_overrides = { formfield_overrides = {
models.TextField: { models.TextField: {
'widget': admin.widgets.AdminTextareaWidget(attrs={ 'widget': admin.widgets.AdminTextareaWidget(attrs={
# 1. REDUCE HEIGHT: Set rows to 1 or 2
# 1. HEIGHT: Set to 1 row to keep it compact (it will expand if they type)
'rows': 2, 'rows': 2,
# 🎨 STYLING
# w-full: Fills the available space
# bg-black: Black background
# text-white: White text (Fixed typo from 'text-blacka')
# border-gray-600: Border color
# leading-normal: Adjusts line height for better vertical centering
'class': 'w-full p-2 border rounded-md bg-black text-white border-gray-600 focus:ring-primary-500 focus:border-primary-500 leading-normal',
'class': (
'border border-gray-300 rounded-md shadow-sm '
'w-full block sm:text-sm '
'bg-white text-gray-900 '
'dark:bg-gray-900 dark:text-white dark:border-gray-700 '
'focus:ring-primary-500 focus:border-primary-500'
),
'placeholder': 'Enter instruction prompt here...',
# 2. INCREASE WIDTH: 'min-width' forces the table cell to expand
'style': 'width: 100%; min-width: 600px; resize: vertical;'
# 2. SIZE FIX:
# - background/color: inherit to keep your color fix
# - min-width: 600px to force the table column to be wide
# - width: 100% to fill that 600px+ space
'style': (
'background-color: inherit; '
'color: inherit; '
'width: 100%; '
'min-width: 700px; ' # Increased slightly for even better UX
'resize: vertical;'
)
}) })
}, },
} }
class AgentSettingsAdmin(ModelAdmin): class AgentSettingsAdmin(ModelAdmin):
def has_add_permission(self, request):
return False
def has_delete_permission(self, request, obj=None):
return False
# ... keep your existing permission and redirect logic ...
def has_add_permission(self, request): return False
def has_delete_permission(self, request, obj=None): return False
def changelist_view(self, request, extra_context=None): def changelist_view(self, request, extra_context=None):
obj, created = self.model.objects.get_or_create(pk=1) obj, created = self.model.objects.get_or_create(pk=1)
@ -50,8 +53,8 @@ class AgentSettingsAdmin(ModelAdmin):
) )
return redirect(url) return redirect(url)
# 2. Add the Stacked Inline
inlines = [AgentPromptInline] inlines = [AgentPromptInline]
# Register
dovoodi_admin_site.register(AgentSettings, AgentSettingsAdmin) dovoodi_admin_site.register(AgentSettings, AgentSettingsAdmin)
project_admin_site.register(AgentSettings, AgentSettingsAdmin) project_admin_site.register(AgentSettings, AgentSettingsAdmin)
Loading…
Cancel
Save