There's a few things to put together -

urls.py needs something like (add a line before the normal admin
line):

(r'^admin/your_report/csv/$',
'yourproject.admin_views.report.csv_report'),
(r'^admin/',     include('django.contrib.admin.urls')),

Then in your admin_views/report.py (or whatever you want to call it)

import csv

@staff_member_required
def csv_report(request):
    # stuff here
    # Create the HttpResponse object with the appropriate CSV header.
    response = HttpResponse(mimetype='text/csv')
    response['Content-Disposition'] = 'attachment;
filename=yournamehere.csv'
    writer = csv.writer(response)
    writer.writerow(['rowheader',
'rowheader','rowheader','rowheader',])
    for obj in obj_list:
        writer.writerow([stuff,stuff,stuff,stuff])
    return response


There are more details within the DjangoBook but that should get you
looking in the right direction.

J

On Nov 9, 10:12 am, GodOfGeeks <[EMAIL PROTECTED]> wrote:
> Hello all,
>
> I would like to add a new button to the searching page called "Convert
> to CSV".
>
> When I press the button, I want to covert the currently displayed
> results to a CSV (Comma separated values)format.
>
> if you could give me some guide lines about how to do this I would be
> really grateful. What I did so far is to copy the
>
> search_form to a new templates folder in my project so now any changes
> i do in the search_form.html is reflected in
>
> in application.
>
> Thanks in advance
>
> Cheers


--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to