I am programming a website builder in Django, and each page has lots of fields to fill out.
Some of them are pretty arcane, and to keep from cluttering up the page they are initially hidden:
class ScriptInlinePage(admin.TabularInline):
model = Page.script.through
extra = 0
fields = ('active', 'script', 'order', )
verbose_name = "script set"
verbose_name_plural = "script sets"
classes = ['collapse']
In the interests of streamlining the page, I have made it so that collapsed inlines are unobtrusive:
Script Sets (Show ▶)
However, these initially-hidden fields can have a disastrous effect if they contain a value and the user is unaware of it.
I am looking for a way to either:
- add a class collapsed but initially visible if not empty, or
- modify the collapse class so that it is only initially collapsed if it's empty
I have tried adding to models.py something like:
def is_empty:
if self.count > 0: return True
else: return False
but I don't know how to use this information in the Admin class to get the effect I want.
Similar question: I thought I saw a way to make an inline collapsible without making it initially collapsed, but after much googling I can't find it. Is that not a thing?