I have a model which looks like 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) # is set and printed to stdout
print(self.mentee_id) # is set and printed to stdout
if Mentorship.objects.is_mentor(self.mentor_id, self.mentee_id):
raise ValidationError(_('This user is already a mentor.'))
The manager has a function to check if someone is already a mentor of another user, which is called while clean()
ing the 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 I always get an exception while accessing the mentor_id
or mentee_id
attribute in exists:
Django Version: 1.6.1
Exception Type: TypeError
Exception Value: exists() got an unexpected keyword argument 'mentor_id'
Is there a reason why I cannot access the _id field within the manager? I just don't understand why the field is accessible in the (unsaved) instance, but not in the manager.