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

class Student(models.Model):

default_selected_student = fields.Boolean(default=False)

if I select one student, the other student should be unselected.  So, there can be only one who is selected.

How can i do that?



아바타
취소
베스트 답변

use api.constrains

@api.constrains('default_selected_student')
def _change_student_status(self):
    if self.default_selected_student:
        students = self.env['<_name>'].search([('id', '!=', self.id)])
        for student in students:
            student.default_selected_student = False

Ok... I think that you could do the the for with a single write, but don't know the exactly how to do it off my head.

Replace the <_name> with your models value for _name.  



아바타
취소

you could probably use api.depends

베스트 답변

for me its not working i am getting error plz solve this error brother


class AcademicYear (models.Model):
        _name = 'edudibonmaster.academicyear'
        _rec_name = 'academicyear'
        _description = 'Academic Year'

        academicyear = fields.Char(string="Academic Year", size = 9, required = True)
        startdate = fields.Date(string="Start Date", required = True)
        enddate = fields.Date(string="End Date", required = True)
        current = fields.Boolean(string = "Active", required = True)

        # constraints unique value


        @api.constrains('current')
        def _change_academic_year(self):
                if self.current:
                        years = self.env['edudibonmaster.academicyear'].search([('id', '!=', self.id)])
                        for year in years:
                                year.current = False

Error :

  File "/opt/odoo/odoo/odoo/service/model.py", line 141, in wrapper
    raise ValidationError(inst[0])
TypeError: 'IntegrityError' object does not support indexing


아바타
취소
작성자

can you send me where the problem is?

ok i will send my module

hi can u help me

작성자

try to use @api.multi

작성자

I mean @api.onchange('current')

작성자 베스트 답변

it works. thanks a lot.

아바타
취소

no problem... than you could like it or select it as the correct answer :)

관련 게시물 답글 화면 활동
1
3월 18
4130
1
1월 20
4946
0
11월 18
2800
1
3월 25
894
2
7월 24
2459