Django provides a File class (django.core.files.File) with File.save() and
File.delete methods. You can associate an action to delete and use
File.delete() to do this task.

2012/9/17 xactive <xacti...@googlemail.com>

> I have little experience with Django/Python but have a problem that I need
> to solve.
>
> Currently I have a button action that allows users of a website to
> download files from a displayed list. I want to add a button to allow users
> to delete the files if required.
>
> The current download button is set up as follows on the page itself:
> <a id="download" href="/portal/files/{{ 
> file.id}}/?action=download">Download</a>
>
> And as far as I can see there is a file called views.py which contains
> code as follows:
> @login_required(login_url='/portal/login/', redirect_field_name=None)
> def file_view(request, id, template_name='portal/file_view.html'):
>     try:
>         f = File.objects.get(pk=id)
>     except File.DoesNotExist:
>         raise Http404
>
>     if request.user not in f.recipients.all() and request.user != f.owner:
>         return HttpResponseForbidden()
>
>     if request.GET.has_key('action') and request.GET['action'] ==
> 'download':
>
>         filename = f.file_obj.name.rsplit('/', 1)[1]
>
>         response = HttpResponse()
>         response['Content-Disposition'] = 'attachment; filename=%s' %
> filename
>         response['Content-Length']      = ''
>         response['X-Accel-Redirect']    = '/%s' % f.file_obj.name
>
>         return response
>
>     return render_to_response(template_name, {
>         'file': f
>     }, context_instance=RequestContext(request))
>
>
> Can somebody please help me to create an action to delete files?
>
> Thanks
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/kckZZ137xigJ.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to