Newforms fields and widgets

3 views
Skip to first unread message

Antares

unread,
Apr 23, 2008, 10:44:25 AM4/23/08
to Django developers
Hello,
I'm developing a custom admin zone named eadmin, and I hope one day
becomes good enough to be part of django. I'm not sure if this group
is the right place, or maybe I should post into django-users. As I'm
developing using django core features I think this is the right place.

I have a form instance in the var form.

for field_name,field_instance in form.fields.iteritems():
if isinstance( field_instance, forms.DateField ):
field_instance.widget = AdminDateWidget()

--
class AdminDateWidget(forms.TextInput):
class Media:
js = ('just_testing.js',)

def __init__(self, attrs={}):
super(AdminDateWidget, self).__init__(attrs={'class':
'DateField'})

--
I took this code from the django newforms-admin branch.
I'm not sure if the class Media is a part of the newforms-admin
framework or it belongs to newforms.
I'd like to load a custom js when use this widget, but the render
function of the widget won't render it.
I've been studying the code but I still need some help.
Can I make it work like this? How can I render the content defined in
the Media class?

Thank you.

Russell Keith-Magee

unread,
Apr 23, 2008, 6:38:37 PM4/23/08
to django-d...@googlegroups.com
On Wed, Apr 23, 2008 at 10:44 PM, Antares <ari...@gmail.com> wrote:
>
> Hello,
> I'm developing a custom admin zone named eadmin, and I hope one day
> becomes good enough to be part of django. I'm not sure if this group
> is the right place, or maybe I should post into django-users. As I'm
> developing using django core features I think this is the right place.

It's not really the right place. Django-dev is for discussing the
development of Django itself; django-users is for discussing how to
use Django itself. In future, please direct user/howto questions
there.

> I have a form instance in the var form.
>

...


> class AdminDateWidget(forms.TextInput):
> class Media:
> js = ('just_testing.js',)

...


> I took this code from the django newforms-admin branch.
> I'm not sure if the class Media is a part of the newforms-admin
> framework or it belongs to newforms.

Media definitions are only available in the newforms-admin branch.
When that branch is merged to trunk, they will become a feature of
newforms. Until then, you can't use Media definitions unless you are
using the newforms-admin branch.

As for rendering - if you just print the widget, you won't get any
javascript. However, if the widget is on a form instance f, and you
pass f to the template, then {{ f.media }} will render as the list of
javascript includes (<script src=""> statements). There is much more
detail in the newforms-admin version of the documentation for
newforms.

Yours,
Russ Magee %-)

Reply all
Reply to author
Forward
0 new messages