I've tried something like this:
def my_callback(field, **kwargs):
if field.name == 'pub_date':
return SplitDateTimeField(**kwargs)
else:
return field.formfield(**kwargs)
class mySplitDateTimeWidget(SplitDateTimeWidget):
def __init__(self, attrs=None):
widgets = (TextInput(attrs={'class': 'vDateField required'}),
TextInput(attrs={'class': 'vTimeField required'}))
MultiWidget.__init__(self, widgets, attrs)
def format_output(self, rendered_widgets):
return u'<span class="dt">%s: %s</span><span class="dt">%s:
%s</span>' %\
(_('Date'), rendered_widgets[0], _('Time'),
rendered_widgets[1]))
def manage_entry(request, object_id=None):
...
baseForm = form_for_instance(entry,
formfield_callback=my_callback)
...
baseForm.base_fields['pub_date'].widget = mySplitDateTimeWidget()
and it works with admin calendar.js!
Cheers
On Jul 21, 5:34 am, "Russell Keith-Magee" <[EMAIL PROTECTED]>
wrote:
> On 7/21/07, jeffhg58 <[EMAIL PROTECTED]> wrote:
>
>
>
> > I am just digging into the newforms functionality. I am looking at the
> >splitdatetimewidget.
> > I am trying to having a different attributes for the first field and
> > the second field, and would like to know how to go about doing it.
>
> I would suggest setting up some purpose based widgets - a DateWidget
> and a TimeWidget - that define their attributes. Then, compose
> yourSplitDateTimeWidgetout of the two custom widgets, rather than using
> two standard TextInputs and trying to pass attributes down to them.
>
> Yours,
> Russ Magee %-)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---