from django.contrib import admin from django.db import models from django.shortcuts import redirect from django.urls import reverse # 1. Change TabularInline to StackedInline from unfold.admin import ModelAdmin, TabularInline from utils.admin import dovoodi_admin_site, project_admin_site from .models import AgentSettings, AgentPrompt class AgentPromptInline(TabularInline): model = AgentPrompt extra = 0 fields = ('is_active', 'content') formfield_overrides = { models.TextField: { 'widget': admin.widgets.AdminTextareaWidget(attrs={ # 1. HEIGHT: Set to 1 row to keep it compact (it will expand if they type) 'rows': 2, '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' ), # 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): # ... 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): obj, created = self.model.objects.get_or_create(pk=1) url = reverse( f"{self.admin_site.name}:{self.model._meta.app_label}_{self.model._meta.model_name}_change", args=[obj.pk] ) return redirect(url) # 2. Add the Stacked Inline inlines = [AgentPromptInline] dovoodi_admin_site.register(AgentSettings, AgentSettingsAdmin) project_admin_site.register(AgentSettings, AgentSettingsAdmin)