# Help needed in Domain

**URL:** https://discuss.tryton.org/t/help-needed-in-domain/1700
**Category:** Developer
**Created:** [August 30, 2019, 6:03am UTC](https://discuss.tryton.org/t/help-needed-in-domain/1700 "2019-08-30T06:03:05Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![kakamble](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/kakamble/32/494_2.png) [@kakamble](https://discuss.tryton.org/u/kakamble)
#### Post date: [August 30, 2019, 6:03am UTC](https://discuss.tryton.org/t/help-needed-in-domain/1700/1 "2019-08-30T06:03:05Z")

</div>

I have a model called ‘exam\_section.exam’. This model has 2 One2Many fields

```
centers = fields.One2Many('exam.centers', 'exam', 'Centers', states={
        'readonly': ~Eval('state').in_(['draft'])
        }, depends=['state'])

```

and

```
employees = fields.One2Many('exam.employees', 'exam', 'Employees', states={
        'readonly': ~Eval('state').in_(['draft'])
        }, depends=['state'])

```

In ‘exam.employees’ model, I have a Many2One field that links to ‘exam.centers’

```
center = fields.Many2One(
    'exam.centers',
    'Center',
    domain=[()] # domain to fetch centers from centers field in 'exam_section.exam'
)

```

I want to select only those centers which are in the centers field of ‘exam\_section.exam’. What should I write in this domain?

---

<div class="post-metadata">

### Author: ![pokoli](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/pokoli/32/22_2.png) [@pokoli](https://discuss.tryton.org/u/pokoli)
#### Post date: [August 30, 2019, 6:36am UTC](https://discuss.tryton.org/t/help-needed-in-domain/1700/2 "2019-08-30T06:36:24Z")

</div>

> [@kakamble](#):
>
> What should I write in this domain?

You should write a function field that returns all the centers of the `exam_section.exam` model and use this field in a in clause:

> [(‘id’, ‘in’, Eval(‘your\_field’)]

Hope it helps

---

<div class="post-metadata">

### Author: ![kakamble](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/kakamble/32/494_2.png) [@kakamble](https://discuss.tryton.org/u/kakamble)
#### Post date: [August 30, 2019, 7:30am UTC](https://discuss.tryton.org/t/help-needed-in-domain/1700/3 "2019-08-30T07:30:35Z")

</div>

I defined a function field as follows

```
centers = fields.Function(
    fields.One2Many(
        'exam.centers',
        'center_hidden',
        'List of centers'
    ),
    'on_change_with_centers'
)

```

and wrote ‘on\_change\_with\_centers’ as follows

```
@fields.depends('exam')
def on_change_with_centers(self, name=None):
    if self.exam and self.exam.centers:
        return self.exam.centers

```

But on starting the server the server gives out the following error

```
Traceback (most recent call last):
File "/home/elf9/workspace/apar_tryton/lib/python3.6/site-packages/Werkzeug-0.15.2-py3.6.egg /werkzeug/serving.py", line 302, in run_wsgi
execute(self.server.app)
File "/home/elf9/workspace/apar_tryton/lib/python3.6/site-packages/Werkzeug-0.15.2-py3.6.egg/werkzeug/serving.py", line 290, in execute
application_iter = app(environ, start_response)
File "/home/elf9/workspace/apar_tryton/lib/python3.6/site-packages/trytond-5.0.8-py3.6.egg/trytond/wsgi.py", line 121, in __call__
return self.wsgi_app(environ, start_response)
File "/home/elf9/workspace/apar_tryton/lib/python3.6/site-packages/trytond-5.0.8-py3.6.egg/trytond/wsgi.py", line 127, in __call__
return self.app(environ, start_response)
File "/home/elf9/workspace/apar_tryton/lib/python3.6/site-packages/trytond-5.0.8-py3.6.egg/trytond/wsgi.py", line 100, in wsgi_app
response = cls.response(data, request)
File "/home/elf9/workspace/apar_tryton/lib/python3.6/site-packages/trytond-5.0.8-py3.6.egg/trytond/protocols/jsonrpc.py", line 160, in response
response, cls=JSONEncoder, separators=(',', ':')),
File "/usr/lib/python3.6/json/ __init__.py", line 238, in dumps
**kw).encode(obj)
File "/usr/lib/python3.6/json/encoder.py", line 199, in encode
chunks = self.iterencode(o, _one_shot=True)
File "/usr/lib/python3.6/json/encoder.py", line 257, in iterencode
return _iterencode(o, 0)
File "/home/elf9/workspace/apar_tryton/lib/python3.6/site-packages/trytond-5.0.8-py3.6.egg/trytond/protocols/jsonrpc.py", line 61, in default
return marshaller(obj)
File "/usr/lib/python3.6/json/encoder.py", line 180, in default
o. __class__. __name__ )
TypeError: Object of type 'exam.centers' is not JSON serializable

```

---

<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: [August 30, 2019, 7:31am UTC](https://discuss.tryton.org/t/help-needed-in-domain/1700/4 "2019-08-30T07:31:31Z")

</div>

The returned value for a One2Many Function must be a list of id not a list of instances.

---

<div class="post-metadata">

### Author: ![kakamble](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/kakamble/32/494_2.png) [@kakamble](https://discuss.tryton.org/u/kakamble)
#### Post date: [August 30, 2019, 9:13am UTC](https://discuss.tryton.org/t/help-needed-in-domain/1700/5 "2019-08-30T09:13:55Z")

</div>

It’s working now  
Thanks! 🙂

---

<div class="post-metadata">

### Author: ![system](https://discuss-cdn.tryton.org/uploads/default/original/1X/c6f8ec0a40525cdcd50058c734283450a4b3d38b.png) [@system](https://discuss.tryton.org/u/system)
#### Post date: [September 29, 2019, 9:13am UTC](https://discuss.tryton.org/t/help-needed-in-domain/1700/6 "2019-09-29T09:13:57Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
