跳至内容
菜单
此问题已终结
5 回复
1946 查看

I want to get this effect:

once a user create one record, then this record will never been edited by anybody.

shall I and how?

形象
丢弃
最佳答案

What if you just remove "Edit" option from the form???

Like...

<form string="My Form" edit="false">

UPDATED:12-8-16

After creating record, if you want like some of field are readonly and some of editable than you can achieve it by attrs.(There are many ways to do this: overriding write method, attrs...)

For ex. if you want after creating a record, Nobody edit 'name' and 'last_name' field then

<field name="id" invisible="1"/>
<field name="name" attrs="{'readonly': [('id','!=',False)]}"/><!--This is readonly after creating record-->
<field name="last_name" attrs="{'readonly': [('id','!=',False)]}"/><!--This is readonly after creating record-->
<field name="age"/><!--This can be editable-->


 Hope this will help you.

形象
丢弃
编写者

thank you for your advice

in the fact , i want to set "edit" ="true" when "My Form" is none(means to never been written) and "edit"="false" when "My Form" is something(means to have been written when created)

Just put edit="false" in form, it will allow to create but not edit...Thanks

编写者

So it is

Thank you every much!

编写者

in addtion, shall we just set some fields of this record not be edited?

see my updated answer..

编写者

I see; thank you very much.

最佳答案

Hi,

I've two suggestion both of them uses the magic/automatic field 'id'

* in the views you can set your fields readonly when the field 'id' is not False

* make a record rule affecting the write access when the 'id' is not False

Hope they can helps ... 

形象
丢弃
编写者

thank you for your advice;

for example, in .py

TextTest=fields.Char()

..

in .xml

<field name="TextTest"/>

how shall I modify the code "<field name="TextTest"/>"?

in xml file, you have to add id field in view, and you have to add attrs on fields to make it readonly.

e.g.

<field name="id" invisible="1">

<field name="TextTest" attrs="{'readonly': [('id', '!=', False)]}"/>

编写者

thank you so much; I have tried to do it;

it exactly meet my requirement;

in addition, shall I know what is the mean for ''id'? whether it can do other things?

it is so miraculous。

编写者

I think I know; "id" is the ID of this record which is generated when creating;

Thanks for your time and patience;

thank you very much.

最佳答案

You can take one boolean field which will be invisible all the time.. Keep default false for that boolean field and in create make the boolean field as True and use this field in attrs for all the fields which you want to make readonly after creating a form.

 



形象
丢弃
编写者

thank you for your advice;