# Create one2many elements on a wizard

**URL:** https://discuss.tryton.org/t/create-one2many-elements-on-a-wizard/1002
**Category:** Developer
**Created:** [January 2, 2019, 2:33pm UTC](https://discuss.tryton.org/t/create-one2many-elements-on-a-wizard/1002 "2019-01-02T14:33:17Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![fransuar](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/f/59ef9b/32.png) [@fransuar](https://discuss.tryton.org/u/fransuar)
#### Post date: [January 2, 2019, 2:33pm UTC](https://discuss.tryton.org/t/create-one2many-elements-on-a-wizard/1002/1 "2019-01-02T14:33:17Z")

</div>

Hi everyone,  
I’m trying to make a wizard to import some data from a csv file.

I’m working on a 2 StateView wizard. The first one is used to choose the data file, the second one is used to have a preview of the data to be imported.

The issue is in the second StateView, when I try to fill a one2many field

The code used is like this:

```
class PartyPreview(ModelView):   
    __name__ = 'party.party.preview'
   (.....)
    surname = fields.Char(
                    'Surname',
                    readonly = True
                    )
   (.....)

class PartyStateViewPreview(ModelView):
    'Patient StateView Preview'
    __name__ = 'party.party.stateview.preview'
    
    (.....)
    party_list = fields.One2Many(
                            'party.party.preview',
                            None,
                            'Party Preview',
                            readonly = True
                            )
    (.....)

class PartyCreateWizard(Wizard):
    'Party Create'
    __name__ = 'party.party.create.wizard'
   (.....)  
   #transition state between the first and the second StateView
   def transition_check_imported(self):
        (....)        
        # I know this is the wrong way, but I have no idea on how to make it work
        # when the one2many target to a ModelView class. 
        self.preview_data.party_list.append([{'surname': 'donatella'}])
        (.....)
       return 'preview_data'

   def default_preview_data(self,fields):
        return{
            'party_list': self.preview_data.party_list,
            }

```

And have this trace

```
Traceback (most recent call last):
  File "/site-packages/trytond/model/model.py", line 384, in __getattr__
    return self._values[name]
TypeError: 'NoneType' object is not subscriptable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/site-packages/trytond/wsgi.py", line 70, in dispatch_request
    return endpoint(request, **request.view_args)
  File "/site-packages/trytond/protocols/dispatcher.py", line 41, in rpc
    request, database_name, *request.rpc_params)
  File "/site-packages/trytond/wsgi.py", line 41, in auth_required
    return wrapped(*args, **kwargs)
  File "/site-packages/trytond/protocols/wrappers.py", line 110, in wrapper
    return func(request, pool, *args, **kwargs)
  File "/site-packages/trytond/protocols/dispatcher.py", line 165, in _dispatch
    result = rpc.result(meth(*c_args, **c_kwargs))
  File "/site-packages/trytond/wizard/wizard.py", line 287, in execute
    return wizard._execute(state_name)
  File "/site-packages/trytond/wizard/wizard.py", line 318, in _execute
    result = self._execute(transition())
  File "/site-packages/trytond/modules/health/wizard/import_wizard.py", line 88, in transition_check_imported
    self.preview_data.party_list.append([{'surname': 'donatella'}])
  File "/site-packages/trytond/model/model.py", line 387, in __getattr__
    % (self. __name__ , name, self._values))
AttributeError: 'party.party.stateview.preview' Model has no attribute 'party_list': None

```

Any idea on how to make it work? Is there any modules that makes something similar?

Regards  
Francisco

---

<div class="post-metadata">

### Author: ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)
#### Post date: [January 2, 2019, 6:15pm UTC](https://discuss.tryton.org/t/create-one2many-elements-on-a-wizard/1002/2 "2019-01-02T18:15:11Z")

</div>

You can not set data on a StateView that was not yet displayed.  
Indeed you must only rely on the default value method and use the data from the previous StateView for example.

---

<div class="post-metadata">

### Author: ![fransuar](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/f/59ef9b/32.png) [@fransuar](https://discuss.tryton.org/u/fransuar)
#### Post date: [January 3, 2019, 12:18am UTC](https://discuss.tryton.org/t/create-one2many-elements-on-a-wizard/1002/3 "2019-01-03T00:18:46Z")

</div>

Thank you @ced for the quickly answer, and thank you @nicoe for editing and formating my post  
Actually, I use the default\_preview\_data method, and that works  
Again, thanks
