Replies: 1 comment
-
|
@drivelous The correct place to do this is in the form which will render for each action on a given rule object: class SpecificActionForm(forms.ModelForm):
class Meta:
model = SpecificAction
fields = "__all__"
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
if self.instance and self.instance.pk:
# hide the field, don't remove it
if not self.instance.field1:
field2 = self.fields.get("field2")
if field2:
field2.widget = forms.HiddenInput()
field2.required = False
class ActionInline(StackedPolymorphicInline):
class SpecificActionInline(StackedPolymorphicInline.Child):
model = SpecificAction
form = SpecificActionForm # use your custom form!
model = Action
child_inlines = (SpecificActionInline,) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
This might be more django admin specific but figured I should add here. Hi there,
I need to conditionally render a form field
field2depending on the value of another fieldfield1Usually, I'll do conditional rendering of a fields in the
get_fieldsmethod and check the values ofobj-- in example see HELPHow would I get the
SpecificActioninstance inget_fieldsinstead of theRuleinstance?Thank you in advance
Beta Was this translation helpful? Give feedback.
All reactions