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

Hello Everyone,

I have to try to apply validation on checkbox. In my process they have product with a multiple option.

So how to apply validation on check box for both option one product option must be select otherwise validation error show. my code below :

m1 = []
for m in self.wizard:
 # print "r::::", m , m.services.gold_service
 if m.services:
 aa =(m.check_box,m.services.id)
 m1.append(aa)
 #print "aaa", m1
 if m.check_box not in m1:
 print "hello", m1
 raise ValidationError("a")

and my terminal show 

hello [(False, 3), (True, 3), (True, 4)]

hello [(False, 3), (True, 3), (True, 4), (False, 4)]


Thanks in advanced.

아바타
취소
작성자 베스트 답변

Solution for above problem

@api.multi
def action_optional_flag_add(self):
m1 = []
for m in self.wizard:
if m.services:
aa = (m.services.id, m.check_box)
m1.append(aa)
count_num = dict(Counter(m1))
res_allrecord = []
for val in count_num:
res_allrecord.append(val[0])
list_res = list(set(res_allrecord))

res_True = []
for val in count_num:
if val[1] != False:
res_True.append(val)
count = Counter([x for (x, y) in res_True])
rec5 = dict(count)

for list_val in list_res:
if list_val not in rec5:
rec5[list_val] = 0
output = dict(count)

for key, value in rec5.items():
if value > 1:
raise ValidationError("Please Select Atlease One Item from Flag")
if value == 0:
raise ValidationError("Please Select Atlease One Item from Flag")
아바타
취소
관련 게시물 답글 화면 활동
1
3월 22
7389
3
7월 20
7027
0
11월 19
3457
1
7월 19
8522
0
10월 24
1488