0

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?

2 Answers 2

2

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)).

Sign up to request clarification or add additional context in comments.

4 Comments

..and [notify.email] instead [notify] in the next line.
I'm getting this error. 'QuerySet' object has no attribute 'email'. Any idea?
I've fixed it. It Should be get() not filter(), Like Emovie.objects.get(id=int(emovie_id))
I have a question, after making the changes, django do send more than one mail to the uploader, when a user download the movie once. why is this happening?
0

replace

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

with

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

It will work fine...

2 Comments

emovie_id will be unique for each emovie.. So Above query will work in all condition.
I did what you said before asking for help on SO. It's not working.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.