On Tue, Sep 16, 2008 at 3:13 PM, David Durham, Jr.
<[EMAIL PROTECTED]> wrote:
> Hi all,
>
> I'm working through a simple wizard using the formtools wizard stuff.
> My issue is that my forms don't display with niceties such as date
> time popup and foreign key 'add' options.  Is there something extra
> that has to be done for these features?

So tackling the first issue I've got something working, but I'm not
particularly proud of it.  To get a "DatePicker" on a
models.DateField, I had to kind of hack things up a bit with custom
Model Field:


from django import forms
from django.db.models import DateField

class CSSDateField(DateField):

    def formfield(self, **kwargs):
        defaults = {'widget' : forms.TextInput(attrs={'class':'date'})}
        defaults.update(kwargs)
        return super(DateField, self).formfield(**defaults)


Then in my Model I do something like

class MyModel(models.Model):
    starts_on = CSSDateField()

Then in my form template, I use jquery and do something like:

$("input.date").datetimepicker()


Like I said, I don't really like this solution, and I'm hoping there's
a better one.  My thinking is that the best way would be to hook this
kind of thing into a ModelForm Meta class.  Specifically, the
ModelForm would know to add this css class to DateFields based on some
configuration in the Meta class.  Maybe this already exists, and I
just don't know it.

The other thing I thought is that if I'm going to create a custom
model Field just to add a css class, then it would be better to just
add an argument like widget_attrs={'css' : 'some_class'}.  Maybe a
purist would say, oh, you've coupled your model with your view, and I
kind of agree, so I think the ModelForm magic would be better, but end
the end, there was already a coupling so I really don't care, but want
to define this in one spot.

Thanks in advance.

-Dave








> Just as a simple test, I reduced things to this:
>
> in forms.py:
>
> class EstimateForm1(forms.Form):
>    start_on = forms.DateField(widget=forms.DateTimeInput)
>
> class EstimateWizard(FormWizard):
>    def done(self, request, form_list):
>        return render_to_response('done.html', {
>            'form_data': [form.cleaned_data for form in form_list],
>        })
>
>
> in urls.py
>
>   (r'^estimate/$', EstimateWizard([EstimateForm1])),
>
>
> and wizard.html:
>
> {% extends "admin/base_site.html" %}
>
> {% block content %}
> <p>Step {{ step }} of {{ step_count }}</p>
> <form action="." method="post">
> <table>
> {{ form.as_table }}
> </table>
> <input type="hidden" name="{{ step_field }}" value="{{ step0 }}" />
> {{ previous_fields|safe }}
> <input type="submit" value="Next">
> </form>
> {% endblock %}
>
> Thanks for any help,
> DAve
>

--~--~---------~--~----~------------~-------~--~----~
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