Skip to Content
Menu
Dette spørgsmål er blevet anmeldt
1 Svar
2675 Visninger

Hi,

I want to use one wizard to act on multiple models. Depending on the model the wizard acts on, some fields of the form view have to change. Currently, I have created two views and choose the one I would like to use using the view_id attributes on the action associated to each model. But I have to create two views and this is not very "DRY". Is there any way to get the current model from xml and make some part of the form view visible/invisible depending on it ?

Avatar
Kassér
Bedste svar

Hello,

You can use the action's context to achieve that ...

e.g:

if you've two models model-1 and model-2, you can create two boolean fields [this is just to illustrate the idea] model1, and model2

make them invisible in the wizard's form.

then in your action [e.g for the first model] define the context as :

<field name="context">{'default_model1':1}</field>


And in the wizard's form make your fields invisible depends on that e.g:

<field name="field1" attrs="{'invisible': [('model1', '!=', True)]}"/>


Hope this will help



Avatar
Kassér
Forfatter

Hi and thanks for your response. Yeah it seems to be the right way to do it.