After searching for a while, I can't seem to find any answer for this so I'm asking this question. What I want to is display some values based on a person's salary and a bracket. My models looks like this.
class Employee
salary = models.DecimalField
class Benefit
some_fields
class EmployeeBenefit
employee = models.ForeignKey
benefit = models.ForeignKey
class BenefitVersion
benefit = models.ForeignKey
class BenefitBracket
benefit_version = models.ForeignKey
from_salary = models.DecimalField
to_salary = models.DecimalField
the_fields_I_want_to_display
As you can see it's quite deep, there would be a bunch of querying to do to get to the fields I want.
I basically need to get the employee's salary(which is easy because this is gonna be inside EmployeeAdmin) then get the current benefit of the EmployeeBenefit
list item, then based on the benefit and the employee's salary, get the bracket and then display some of it's fields on the inline
.
I want to display the the_fields_I_want_to_display
on the admin.TabularInline
for EmployeeBenefit
inside my EmployeeAdmin
. I was testing using a forms.ModelForm
in the inline
and modifying it's contents using get_form
based on this answer but django is not calling get_form
. I also previously tried using calculated_fields
but it's not being rendered as well.
I'm using django 3.1.7 btw
Edit:
I found this and try it out right now. I think it has potential but unfortunately the obj
that get_formset
gives is Employee
so I still need to find a way to get the right EmployeeBenefit
for the list item