Reputation: 1519
For every movie download on my webapp, I want to inform the uploader through mail that his movie have been downloaded. I wrote the below code, it seems I'm finding it hard to get the query right.
AttributeError at /download/
'unicode' object has no attribute 'email'
Models:
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
How can I go about this?
Upvotes: 0
Views: 89
Reputation: 2555
replace
notify=Emovie.objects.get(id=emovie_id).email
with
notify=Emovie.objects.filter(id=emovie_id.email)
It will work fine...
Upvotes: 0
Reputation: 122536
The error happens here: Emovie.objects.filter(id=emovie_id.email)
.
emovie_id
is a unicode (string) object which means you can't do .email
on it. Given that you want to filter on id=
I think you meant to write: Emovie.objects.get(id=int(emovie_id))
.
Upvotes: 2