Tuesday, January 12, 2021

Admin - is it possible to make fieldsets description dynamic

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.


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/e60eb5a6-89c0-67df-0eb8-72ef693d2bf5%40dewhirst.com.au.

No comments:

Post a Comment