Admin - is it possible to make fieldsets description dynamic

29 views
Skip to first unread message

Mike Dewhirst

unread,
Jan 13, 2021, 1:54:31 AM1/13/21
to Django users
In the Django 2.2 Admin, the description in fieldsets is very useful for
providing advice to a user.

However, in one of my models there are now a couple of "states" in which
it could be and each really calls for a different piece of advice.

I know in ModelAdmin.fieldsets I can do "description": description(), to
get a single piece of advice but I really need to get access to the
model instance in that callable so I can detect the "state" and return
different advice.

I have looked at admin.helpers.FieldSet but cannot see any reference to
the model instance in there.

It would be ideal to have a model method which returned a description
and have the helper call that if admin.ModelAdmin didn't have a
description dict in its fieldsets attribute.

Any hints will be appreciated

Thanks

Mike

--

Signed email is an absolute defence against phishing. This email has
been signed with my private key. If you import my public key you can
automatically decrypt my signature and be sure it came from me. Just
ask and I'll send it to you. Your email software can handle signing.


OpenPGP_signature
Reply all
Reply to author
Forward
0 new messages