selection field

37 views
Skip to first unread message

Cato Nano

unread,
Dec 18, 2017, 6:08:55 AM12/18/17
to tryton
Now that a list of entities represented by my model get correctly shown, I want to add a selection field to my model. Like this


tipo = fields.Selection('tipo', [
('M', 'Male')
('F', 'Female')
],
)

I copied this from the manual, here
http://doc.tryton.org/4.6/trytond/doc/ref/models/fields.html#ref-models-fields

when updating the module like this

:~/tributi$ sudo python3 setup.py develop
:~/tributi$ sudo trytond-admin -c /etc/tryton/trytond.conf -d tryton -u tributi

i get this error


Traceback (most recent call last):
File "/usr/bin/trytond-admin", line 21, in <module>
admin.run(options)
File "/usr/lib/python3/dist-packages/trytond/admin.py", line 54, in run
installdeps=options.installdeps)
File "/usr/lib/python3/dist-packages/trytond/pool.py", line 142, in init
self.start()
File "/usr/lib/python3/dist-packages/trytond/pool.py", line 95, in start
register_classes()
File "/usr/lib/python3/dist-packages/trytond/modules/__init__.py", line 373, in register_classes
mod_file, pathname, description)
File "/usr/lib/python3.6/imp.py", line 245, in load_module
return load_package(name, filename)
File "/usr/lib/python3.6/imp.py", line 217, in load_package
return _load(spec)
File "<frozen importlib._bootstrap>", line 684, in _load
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/admin/tributi/build/lib/trytond/modules/tributi/__init__.py", line 2, in <module>
from .bolletta import Bolletta
File "/home/admin/tributi/build/lib/trytond/modules/tributi/bolletta.py", line 6, in <module>
class Bolletta(ModelSQL, ModelView):
File "/home/admin/tributi/build/lib/trytond/modules/tributi/bolletta.py", line 13, in Bolletta
('F', 'Female')
TypeError: 'tuple' object is not callable


Thanks in advance !

Gonzalo González Domínguez

unread,
Dec 18, 2017, 6:35:08 AM12/18/17
to tryton
First param is the options, second the label i think ...

Mark Shane Hayden

unread,
Dec 18, 2017, 11:27:03 AM12/18/17
to try...@googlegroups.com


On Dec 18, 2017 04:08, "Cato Nano" <cato...@gmail.com> wrote:
Now that a list of entities represented by my model get correctly shown, I want to add a selection field to my model. Like this


    tipo = fields.Selection('tipo', [
        ('M', 'Male')
        ('F', 'Female')
    ],
    )

You need to separate your tuples with commas in the selection list like this:
    ('M', 'Male),
    ('F', 'Female')

without the comma it looks to the Python interpreter like the second tuple is parameters and the first tuple is a function hence the error.

--
You received this message because you are subscribed to the Google Groups "tryton" group.
To view this discussion on the web visit https://groups.google.com/d/msgid/tryton/8ddc439a-f4cb-49bc-a5aa-09d7e4201e58%40googlegroups.com.

Cato Nano

unread,
Dec 19, 2017, 1:38:05 AM12/19/17
to tryton
thank you people

I managed to make it work

I found a selection field in the "sales" module and copied that code and adapted it

Thats how I discovered that the options list ought to be the first argument

For now I have no "form" view for my bolletta so I can t test the drop down menu

But the field shows up in a tree view, so I guess it s ok

Thanks !

Cato Nano

unread,
Dec 19, 2017, 5:29:52 AM12/19/17
to tryton
ok, now I also have a form view and the selction field works like a charm !!
Reply all
Reply to author
Forward
0 new messages