I am trying to filter the objects based on many to many field.
profiledata = UserProfile.objects.get(user=newdata)
role = profiledata.role
ib = IdealBehaviour.objects.filter(cbs_role = cbsrole)
a_questions = Questions.objects.filter(Q(role=role) & Q(ideal_behaviour=ib))
Here i am not getting a_questions. While doing this i am getting error.
(1242, 'Subquery returns more than 1 row')
Django Version: 1.5.1
Exception Type: DatabaseError
Exception Value:
(1242, 'Subquery returns more than 1 row')
Exception Location: /usr/lib/python2.7/dist-packages/MySQLdb/connections.py in defaulterrorhandler, line 36
Python Executable: /usr/bin/python
Python Version: 2.7.6
I tried using _in lookup also
a_questions = Questions.objects.filter(Q(role=role) & Q(ideal_behaviour_in=ib))
Getting error
Cannot resolve keyword 'ideal_behaviour_in' into field. Choices are: created_time, id, ideal_behaviour, question, role
I dont know what wrong i am doing. ib is getting filtered properly as IdealBehaviour has many to many relationship with CBSROLE Please help me out for this.