Blog Archive for July 17, 2010

TextArea in Django Form

July 17, 2010

If you need to define a char field in a Django form so that it is a textarea, use the following in the form definition:

class ResultsForm(forms.Form):
    results = forms.CharField(widget=forms.Textarea(attrs={'width':"100%" …

Changing queryset of a ModelChoiceField

July 17, 2010

Sometimes there's a need to change the queryset used in a ModelChoiceField at runtime. This can be done by overriding the init function on the form:

class ResultsForm(forms.Form):
    event_1 = forms.ModelChoiceField(queryset=Contest.objects.none(), required=True …