You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
2.1 KiB
57 lines
2.1 KiB
from django.contrib import admin
|
|
from django.db import models
|
|
from django.shortcuts import redirect
|
|
from django.urls import reverse
|
|
from unfold.admin import ModelAdmin, TabularInline
|
|
from utils.admin import dovoodi_admin_site, project_admin_site
|
|
from .models import AgentSettings, AgentPrompt
|
|
from unfold.contrib.forms.widgets import WysiwygWidget
|
|
|
|
|
|
class AgentPromptInline(TabularInline):
|
|
model = AgentPrompt
|
|
extra = 0
|
|
fields = ('is_active', 'content')
|
|
|
|
formfield_overrides = {
|
|
models.TextField: {
|
|
'widget': admin.widgets.AdminTextareaWidget(attrs={
|
|
# 1. REDUCE HEIGHT: Set rows to 1 or 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',
|
|
|
|
'placeholder': 'Enter instruction prompt here...',
|
|
|
|
# 2. INCREASE WIDTH: 'min-width' forces the table cell to expand
|
|
'style': 'width: 100%; min-width: 600px; resize: vertical;'
|
|
})
|
|
},
|
|
}
|
|
|
|
class AgentSettingsAdmin(ModelAdmin):
|
|
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)
|
|
|
|
inlines = [AgentPromptInline]
|
|
|
|
# Register
|
|
dovoodi_admin_site.register(AgentSettings, AgentSettingsAdmin)
|
|
project_admin_site.register(AgentSettings, AgentSettingsAdmin)
|