Issue
Is there a way how can I make one of the fields in admin.TabularInline
conditional?
for example
class ParameterInline(admin.TabularInline):
form = ParameterForm
fields = ["ParameterA", "ParameterB"]
What if I wanted to display the ParameterB
only if something else was set to, for example, True
?
Thanks in advance.
Solution
You can achieve this by overriding the get_fields
method:
class ParameterInline(admin.TabularInline):
form = ParameterForm
fields = ["ParameterA"]
def get_fields(self, request, obj=None):
fields = super(ParameterInline, self).get_fields(request=request, obj=obj)
if True:
return fields + ['ParameterB']
return fields
Answered By - Marcell Erasmus Answer Checked By - Timothy Miller (PHPFixing Admin)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.