django: got an unexpected keyword argument while accessing ForeignKey _id-Field in Manager -


i have model looks this:

class mentorship (models.model):     mentor = models.foreignkey(settings.auth_user_model, related_name='mentor_user_id')     mentee = models.foreignkey(settings.auth_user_model, related_name='mentee_user_id')      objects = mentorshipmanager()      def clean(self):         print(self.mentor_id)  # set , printed stdout         print(self.mentee_id)  # set , printed stdout          if mentorship.objects.is_mentor(self.mentor_id, self.mentee_id):             raise validationerror(_('this user mentor.')) 

the manager has function check if mentor of user, called while clean()ing instance:

def is_mentor_for_goal(self, mentor_id, mentee_id, personal_goal_id):     if self.exists(mentor_id=mentor_id, mentee_id=mentee_id):         return true     else:         return false 

however exception while accessing mentor_id or mentee_id attribute in exists:

django version:     1.6.1 exception type:     typeerror exception value:    exists() got unexpected keyword argument 'mentor_id' 

is there reason why cannot access _id field within manager? don't understand why field accessible in (unsaved) instance, not in manager.

a few things mentor__id work in queryset methods, not things print. should use pk instead of id, here how work:

class mentorship(models.model):     mentor = models.foreignkey(settings.auth_user_model, related_name='mentor_user_id')     mentee = models.foreignkey(settings.auth_user_model, related_name='mentee_user_id')      objects = mentorshipmanager()      def clean(self):         print(self.mentor.pk)  # set , printed stdout         print(self.mentee.pk)  # set , printed stdout          if mentorship.objects.filter(mentor=self.mentor).exists():             raise validationerror(_('this user mentor.'))  def is_mentor_for_goal(self, mentor_id, mentee_id, personal_goal_id):     return self.exists(mentor__pk=mentor_id, mentee__pk=mentee_id) 

Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -