콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
3 답글
47042 화면

When I create a custom model in the web GUI, how can I mark a field as "unique", so that the database will never create a second row with the same field value?

아바타
취소
베스트 답변

You can only do this when you create your field via Python.

See https://accounts.openerp.com/forum/Help-1/question/16386

_sql_constraints = [
                     ('field_unique', 
                      'unique(field)',
                      'Choose another value - it has to be unique!')
]

Note that if there are existing records for the model in the database, then any field values have to be unique, or this will fail and OpenERP will do nothing to enforce the constraint for new records.

아바타
취소
작성자

Thanks, so I will have to write a Python module for my table. Maybe it would be a nice enhancement if there would be a "unique" flag in the GUI as well. I assume, that unique fields are needed often (serial numbers, order numbers, etc.).

베스트 답변

Hi,

add a sql constraint to your model :

_sql_constraints = [
        ('uniq_name', 'unique(stuff_name)', "A stuff already exists with this name . Stuff's name must be unique!"),
    ]

Best regards

아바타
취소
작성자

Thanks, too!

베스트 답변
_sql_constraints = [
        ('uniq_name', 'unique(your_field_name)', "You Entered data is already exists with this name. Please give data must be unique!"),
    ]
아바타
취소
관련 게시물 답글 화면 활동
1
3월 15
7272
2
3월 15
6503
2
3월 22
2803
0
3월 24
3386
3
6월 17
7241