#Show attribute of a field in a tabular inline

3 messages · Page 1 of 1 (latest)

hollow kelp
#

I'm listing some FKs (or rather, objects that have the object as FK) in a tabular inline.

The "one" model is Foo. The model that has Foo as FK is Bar, and Bar is shown as an inline in Foo. Bar has a field Baz. All of this shows by default, but I would like to show a separate (ideally read-only) field with an attribute of Baz (let's call it Happy).

So the inline should show Bar.fieldone, Bar.fieldtwo, Bar.baz (fieldthree), and Bar.baz.happy.

I tried putting baz__happy in the fields for the inline, but that didn't compile.

It's not a feasible solution to simply put Happy in the string representation of Baz.

golden stone
#

I'd try adding a method baz_happy which returns the value you want to show on the tabular inline or on the model, and putting "baz_happy" into the inlines readonly_fields list.

hollow kelp
#

yeah that worked. actually had to add it to both fields and readonly_fields. if only in fields it didn't compile; if only in readonly it didn't display

cheers 💚