On Friday, October 3, 2014 2:41:58 PM UTC-3, Mariano Ramon wrote:
>
>
> I have doctor and team and doctorteam, every doctor can belong to many 
> teams and teams can have many doctors
>
> They are defined like this (removed/edited things for brevity/clarity):
>
>
> class Team(ModelSQL, ModelView):
>     'Etc'
>     __name__ = 'team'
>
>     doctors = fields.Many2Many('team_doctor', 'team', 'doctor', 'Doctors' )
>
>
> class TeamDoctor(ModelSQL, ModelView):
>     'etc'
>     __name__ = 'team_doctor'
>
>     team = fields.Many2One('team','Team', required=True)
>     doctor = fields.Many2One('doctor', 'Doctor', required=True)
>     
>     def search(cls, name, clause):
>         pass
>
>
> class Doctor(ModelSQL, ModelView):
>     'etc'
>     __name__ = 'doctor' 
>     teams = fields.One2Many('team_doctor', 'doctor', 'TEAMs')
>
>
> this seems to work except when I try to access Doctor from any view I get 
> the error when search is not defined in TeamDoctor
> AttributeError: type object 'doctor_doctorgroup' has no attribute 'search'
>
>
>
Correction: error says AttributeError: type object 'team_doctor' has no 
attribute 'search'

 

> I dont know how to define that method search, I always get
> unbound method search() must be called with doctor_doctorgroup instance as 
> first argument (got list instance instead()
> no matter what
>
>
Correction: error says unbound method search() must be called with 
team_doctor instance as first argument (got list instance instead()

 

> What I'm doing wrong?
>
>
>

Ok I read about unbound functions and I was missing the decorator.. now 
when I define the search method like this:

    @classmethod
    def search(self, clause=[('id', '!=', None)], order=[('team', 'ASC')]):
        pass


I get the error:

 File "............../trytond-3.2.2/trytond/model/fields/one2many.py", line 
98, in get
    targets = list(chain(*targets))
TypeError: 'NoneType' object is not iterable


which I guess because there isn't bringing any records, but shouldn't just 
show an empty list? I have the feeling that I'm doing something really 
wrong. In the documentation doesn't say anything about defining that search 
function when defining many2many.











> Thanks!
> Mariano
>
>

Reply via email to