views:

160

answers:

1

I have a site with users who can take terms at University:

class Term(models.Model):
    school = models.ForeignKey(School)
    name = models.CharField(max_length=200)
    isPrimaryTerm = models.BooleanField()
    date = models.DateField()

class MyUser(models.Model):
    user = models.ForeignKey(User, unique=True)
    takingReqSets = models.ManyToManyField(RequirementSet, blank=True)
    takingTerms = models.ManyToManyField(Term, blank=True)
    takingCourses = models.ManyToManyField(Course, through=TakingCourse, blank=True)
    school = models.ForeignKey(School)

When I try to add to the set of terms the user is taking, I get an error:

def add_term(request):
    curr_user = User.objects.get(id=request.GET['pk'])
    term = RequirementSet.objects.filter(pk=request.GET['term_pk']).get()

    curr_user.get_profile().takingTerms().add(term)
    curr_user.get_profile().save()

This raises a TypeError:

'ManyRelatedManager' object is not callable

What am I doing wrong?

+2  A: 

Try:

curr_user.get_profile().takingTerms.add(term)

When you write takingTerms() you are actually calling takingTerms as method, and since that attribute is an instance of ManyRelatedManager and not a callable method you get that error.

rebus