当我尝试使用其他表中的外键检索数据时,出现以下异常:
'User' object has no attribute 'UserFeed_set'
看法 :
def user_page(request, username):
try:
u = User.objects.get(username=username)
except User.DoesNotExist:
raise Http404(u'Requested user not found.')
feeds = u.UserFeed_set.all()
variables = RequestContext(request, {
'username' : username,
'feeds' : feeds
})
return render_to_response('user_page.html', variables)
模型.py:
from django.contrib.auth.models import User
class AllFeeds(models.Model):
url = models.CharField(unique=True, max_length=40)
def __unicode__(self):
return self.url
class UserFeed(models.Model):
user = models.ForeignKey(User)
myfeeds = models.ForeignKey(AllFeeds)
def __unicode__(self):
return u'%s %s'%(self.user.username,self.link.url)