Skip to Content
Menu
This question has been flagged
5 Replies
1659 Views

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?

Avatar
Discard
Best Answer

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.

Avatar
Discard
Author

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

Author

So it is

Thank you every much!

Author

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

see my updated answer..

Author

I see; thank you very much.

Best Answer

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 ... 

Avatar
Discard
Author

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)]}"/>

Author

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。

Author

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.

Best Answer

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.

 



Avatar
Discard
Author

thank you for your advice;