2013-11-20 2 views
0

웹 응용 프로그램에서 모든 영화를 다운로드 할 때마다 업 로더에게 영화가 다운로드되었음을 우편으로 알려야합니다. 나는 아래의 코드를 썼다. 나는 질의를 제대로하기가 어렵다고 생각한다.장고에서 객체를 검색 할 때 AttributeError가 발생했습니다.

AttributeError at /download/ 

'unicode' object has no attribute 'email' 

모델 :

class Emovie(models.Model): 
    User=models.ForeignKey(User) 
    movie_file=models.FileField(upload_to='miiv') 
    movie_name=models.CharField(max_length=50) 
    email=models.EmailField() #email of the uploader 
    #other fields follows 

Views.py

@login_required 
def document_view(request, emovie_id, urlhash): 
    document=Emovie.objects.get(id=emovie_id, urlhash=urlhash) 
    downstats=Emovie.objects.filter(id=emovie_id, urlhash=urlhash).update(download_count=F('download_count')+1) 
    #where email notification starts 
    notify=Emovie.objects.filter(id=emovie_id.email) 
    send_mail('Your file has just been downloaded','this works','[email protected]',[notify]) 
    response = HttpResponse() 
    response["Content-Disposition"]= "attachment; filename={0}".format(document.pretty_name) 
    response['X-Accel-Redirect'] = "/protected_files/{0}".format(document.up_stuff) 
    return response 

어떻게 이것에 대해 갈 수 있나요?

답변

2

여기에서 오류가 발생합니다 : Emovie.objects.filter(id=emovie_id.email).

emovie_id은 유니 코드 (문자열) 개체이므로 .email을 사용할 수 없습니다. id=을 필터링하려고 할 때 나는 당신이 다음과 같이 쓸 것이라고 생각합니다 : Emovie.objects.get(id=int(emovie_id)).

+1

'.. 그리고 [notify.email]'대신에 '[알릴] 교체'다음 라인 . – mariodev

+0

@mariodev : 예, 그렇습니다. 고맙습니다. –

+0

이 오류가 발생합니다. 'QuerySet'객체에는 'email'속성이 없습니다. 어떤 생각? – picomon

0

notify=Emovie.objects.filter(id=emovie_id.email) 

이는 잘 작동과

notify=Emovie.objects.get(id=emovie_id).email 

는 ...

+0

emovie_id는 각각의 emovie에 대해 고유 할 것입니다 .. 그래서 위의 쿼리는 모든 조건에서 작동합니다. – Nilesh

+0

나는 SO에 도움을 청하기 전에 당신이 말한 것을했습니다. 작동하지 않습니다. – picomon

관련 문제