views:

44

answers:

1

Hi All,

I've recently been developing on the django platform and have stumbled upon Django Forms (forms.Form/forms.ModelForm) as ways of creating <form> html.

Now, this is brilliant for quick stuff but what I'm trying to do is a little bit more complicated. Consider a DateField - my current form has fields for day, month and year and constructs a python date object from that. However, a django form creates a single textbox in which the correct format (say 2010-06-15) must be entered. As another example, for large fields I need to replace <input> with <textarea>.

I'd like to take advantage of Django's forms for simple validation but I need something simpler for my users. So my question is: can I intercept the rendering of one of these objects to write out the html as I like? If so, do I have to do all the writing myself or can I only do those objects I wish to re-write?

Thanks in advance.

+1  A: 

Yes, you can.

You just have to override the default widget that gets rendered for the field.
Look in the docs for all the necessary information.

You can also define custom widgets if the necessity arises, e.g. a date field rendered with dropdowns instead of a single text field.

Google for them, there are already some pretty nifty widgets out there :)

Agos
Aaaah, thankyou! Knew it shouldn't be too difficult to do... just couldn't find it for looking.
Ninefingers