3 ms·
At least part of the problem is that it looks so, so weird, and it's really tightly bound to models. This is like the most customized admin i've made and it's s
by andkon 9y ago
At least part of the problem is that it looks so, so weird, and it's really tightly bound to models. This is like the most customized admin i've made and it's still pretty simple, but it sure doesn't feel that easy to reason about when you look at it (it's an admin page that lets you link a specific admin-page input to a model, then display it in a list that you can add to):
from django.contrib import admin
from django.forms import Textarea
from .models import *
# Register your models here.
class BotTextInline(admin.StackedInline):
model = BotReplyContent
extra = 1
fieldsets = [
(None, {'fields': ('message_type', 'text', ('template_text', 'example_text',), 'order',)}),
('Actions and inputs', {'classes': ('collapse,'), 'fields': ('action_type', 'input_type',)})
]
# readonly_fields = ['input_type_ptr']
class BotReplyAdmin(admin.ModelAdmin):
fieldsets = [
(None, {'fields': ('state', 'intent', 'context', 'description', 'next_state',)}),
]
formfield_overrides = {
models.CharField: {'widget': Textarea()}
}
list_display = ('state', 'intent', 'context', 'description',)
save_as = True # lets you save the content on screen as a new id
inlines = [BotTextInline]
admin.site.register(BotReply, BotReplyAdmin)
```
- Daishiman 9y agoThis is a trivial amount of customization. Yes, you have to know what the class fields do. But you just saved yourself days of having to make your own CRUD view from scratch.
- andkon 9y agoTotally trivial. And yet, I still can barely parse what's going on in there.
- Daishiman 9y agoBut proportional to the docs and total customizability and sheer mass of code and functionality that happens. You're getting free authentication for an admin + free UI + a fully customizable list view + customizable create/update view + delete with a useful confirmation dialog + trivial field search + trivial filters of all sorts include date drill-downs. It's a huge amount of things to do by hand.