これはビューの私のコードです:
@login_required
def get_top(type):
o = Work.objects.filter(types = "Fan Fiction").order_by("-date_updated")[:10]
list = []
for o in o:
l.title = o.title
l.href = "/" + o.id
list.append(l)
return l
@login_required
def main_home(request):
fanfiction = get_top("ff")
poetry = get_top("pw")
originalwork = get_top("ow")
return render_to_response("Main/main_home.html", {'STATIC_URL':STATIC_URL, "poetry":poetry, "fan":fanfiction, "original":originalwork})
これはモデルのコードです:
class Work(models.Model):
title = models.CharField(max_length=30)
summery = models.TextField()
user = models.ForeignKey(User)
date_published = models.DateField()
date_updated = models.DateField()
one_shot = models.BooleanField()
completed = models.BooleanField()
TYPES = (
('FF', 'Fan Fiction'),
('OF', 'Original Work'),
('PW', 'Poetry Work'),
)
types = models.CharField(max_length=2, choices=TYPES)
fandom1 = models.ForeignKey(Book, blank = True, null= True, related_name='f_1')
fandom2 = models.ForeignKey(Book, blank = True, null= True, related_name='f_2')
def __unicode__(self):
return self.title + '-' + self.user.email
これはエラーです: 'str' object has no attribute 'user'
at "get_top("ff")"