views:

17

answers:

0

Hey,

I'm trying to add an Export CSV function to Django Admin. So far I've managed the following:
1. Added an 'Export CSV' link to the admin change_list.html.
2. On the export page, I start off by creating the required model from two separate parts of the URL using model = get_model(app_name, module_name).
3. From this model I first create a Formset using modelformset_factory(model, exclude=(ExcludeFields))
4. I then create a form using form = Formset()
so at this point my code looks like this:

from django.db.models import *  
from django.forms.models import modelformset_factory, ModelForm

exportModel = get_model(app_name, module_name)
exportFormSet = modelformset_factory(exportModel, exclude=(csvExcludeFields))
exportForm = exportFormSet()

At this point I can pass exportForm into my template and loop through it to output the form. Fields like CharField, ForeignKey, IntegerField and BooleanField are all rendering correctly with the correct input types. However, DateField, TimeField and DateTimeField are all rendering as plain text input whereas I'd like them to render as the date, time or datetime widget that we see in the standard change_form. I think I've narrowed my problem down to one of two things:
1. Although I have a DateTimeField in my model, it doesn't seem to know what widget (AdminSplitDateTime) to use when it comes to rendering within my custom template
or
2. The DateTimeField knows what widget to use, but I haven't been able to associate the correct media (ie js & css files) with it to get the AdminSplitDateTime widget to render correctly.

Can anyone point me in the right direction here, or suggest if I'm perhaps going about this in completely wrong way?