0

我正在尝试创建一个函数来列出所有关注特定用户的人,但我一直遇到这个我似乎无法解决的错误。有人可以帮我一把吗:)

 error 

 AttributeError at /Follow/

 'function' object has no attribute 'objects'

 Request Method:    GET
 Request URL:   http://127.0.0.1:8000/Follow/
 Django Version:    1.5.1
 Exception Type:    AttributeError
 Exception Value:   

 'function' object has no attribute 'objects'
 Traceback:
 File "C:\Python27\lib\site-packages\django\core\handlers\base.py" in get_response
   115.                         response = callback(request, *callback_args, **callback_kwargs)
      File "C:\Python27\lib\site-packages\endless_pagination\decorators.py" in decorated
   35.             return view(request, *args, **kwargs)
 File "C:\Python27\lib\site-packages\django\contrib\auth\decorators.py" in _wrapped_view
   25.                 return view_func(request, *args, **kwargs)
 "C:\mysite\pet\views.py" in Followings
   97.     followers = Follow.objects.followers(user)

 Exception Type: AttributeError at /Follow/
 Exception Value: 'function' object has no attribute 'objects'

楷模

 class Follow(models.Model):
     """ Model to represent Following relationships """
     follower = models.ForeignKey(AUTH_USER_MODEL, related_name='following')
     followee = models.ForeignKey(AUTH_USER_MODEL, related_name='followers')
     created = models.DateTimeField(default=timezone.now)

     objects = FollowingManager()

     class Meta:
         verbose_name = _('Following Relationship')
         verbose_name_plural = _('Following Relationships')
         unique_together = ('follower', 'followee')

     def __unicode__(self):
         return "User #%d follows #%d" % (self.follower_id, self.followee_id)

     def save(self, *args, **kwargs):
         # Ensure users can't be friends with themselves
         if self.follower == self.followee:
        raise ValidationError("Users cannot follow themselves.")
         super(Follow, self).save(*args, **kwargs)




 class Person(models.Model):



     user = models.ForeignKey(User)
     name = models.CharField(max_length=30, blank=True)

     def __unicode__(self):
         return self.user.username

意见

 @page_template('pagination.html')
 @login_required
 def Followings(request,template='following.html', extra_context=None):
     followers = Follow.objects.followers(user)
     person = Person.objects.filter(user__in=followers)
     context = {
        'page_template': 'pagination.html',
         'person' :Person.objects.filter(user__in=followers),

    }
     extra_context = {'person':person,}
     if extra_context is not None:
    context.update(extra_context)

     return render_to_response(
    template, context, context_instance=RequestContext(request))

网址

         url(
             r'^Follow/$',
             'pet.views.Followings',
             name= 'Followings',
         ),
4

1 回答 1

0

改变

followers = Follow.objects.followers(user)

followers = request.user.followers.all()
于 2013-07-25T09:05:14.807 回答