when I try :
当我尝试:
StudyRecord.object.filter(user__name__contains= id )
the django cast the following error :
django投下以下错误:
AttributeError at /tag_study/my_infor/ type object 'StudyRecord' has no attribute 'object'
/ tag_study / my_infor / type对象'StudyRecord'中的AttributeError没有属性'object'
Traceback Switch to copy-and-paste view
回溯切换到复制粘贴视图
C:\Python27\lib\site-packages\django-1.7.3py2.7.egg\django\core\handlers\base.py in get_responseresponse = wrapped_callback(request, *callback_args, **callback_kwargs) ...
▶ Local vars
c:\mystudio\tag_study\views.py in my_inforurrent_book = StudyRecord.object.filter(user__name__contains= id ) ...
▶ Local vars
the StudyRecord models:
StudyRecord模型:
class StudyRecord(models.Model):
user = models.ForeignKey(User)
book = models.CharField(max_length=128)
starttime= models.DateTimeField()
endtime = models.DateTimeField()
def save(self, *args, **kwargs):
self.slug = slugify(self.number)
super(StudyRecord, self).save(*args, **kwargs)
def __unicode__(self): #For Python 2, use __str__ on Python 3
return self.book
and this is the views
这是意见
def my_infor(request):
if request.method == "GET":
if request.user.is_authenticated():
id = request.user.id
StudyRecord.object.filter(user__name__contains= id )
return HttpResponse(current_book)
else:
return HttpResponse("error2")
context = RequestContext(request)
return render_to_response('tag_study/my_infor.html', context)
2 个解决方案
#1
1
It should be objects, not object
它应该是对象,而不是对象
#2
0
When you get data from db, you need a Manager
through which you can construct the QuerySet
you wanted.
从db获取数据时,需要一个Manager,您可以通过它来构造所需的QuerySet。
Each model has at least one Manager, and it’s called objects by default.
每个模型至少有一个Manager,默认情况下称为对象。
More info here.
更多信息在这里。
#1
1
It should be objects, not object
它应该是对象,而不是对象
#2
0
When you get data from db, you need a Manager
through which you can construct the QuerySet
you wanted.
从db获取数据时,需要一个Manager,您可以通过它来构造所需的QuerySet。
Each model has at least one Manager, and it’s called objects by default.
每个模型至少有一个Manager,默认情况下称为对象。
More info here.
更多信息在这里。