I am displaying a django form and I want to prepare some field data before it is passed to to be rendered. In the django docs, I see plenty of places where form data is accessed, but none where form data is set before display.
Any thoughts or suggestions on how to do this?
Here's an example similar to the django docs.
-----------forms.py--------------
class BookForm(ModelForm):
author = forms.CharField(max_length=100)
title = forms.CharField(max_length=3,
widget=forms.Select(choices=TITLE_CHOICES))
birth_date = forms.DateField(required=False)
-----------views.py--------------
def author_view(request):
if request.method == 'POST':
# DO My processing...
form = BookForm()
# How can I edit, or preset my form fields here?
c = Context({
'form': form,
})
return prepCxt(request, 'book.html', c) # Wrapper for easy display