0

I have a ModelForm in django that generates a load of floating point field options. This is being used for a ratings system, but I'd like to allow users to select "skip" on any of the catagories (NULL is allowed in the DB for each field). Is there a native class in django for something like this that I'm missing? If not, what would be the best way to achieve this e.g. such that

{% for field in form %}
<tr>
<td><label for="{{ field.label }}" class="control-label">{{ field.label }}</label></td>
<td>{{ field }}</td>
<td></td>
</tr>
{% endfor %}

Would allow for something like {{ field.skip }} with a checkbox in the last column of a table?

Cheers

radpotato
  • 1,332
  • 1
  • 12
  • 20

1 Answers1

0

There is required=False

name = forms.CharField(max_length=100,required=False)

This will make the field optional

Edit: For a Model Form, this might help you:

Django: Make certain fields in a ModelForm required=False

Community
  • 1
  • 1
Aswin Murugesh
  • 10,831
  • 10
  • 40
  • 69
  • Yeah, I've tried this. Thing is, I wanted to have an explicit checkbox such that users aren't confused and know that they are purposefully skipping an item. – radpotato Feb 09 '15 at 08:01
  • @radpotato I believe you will have to bring in Mr. Javascript for this job. http://www.tutorialrepublic.com/faq/show-hide-divs-based-on-checkbox-selection-in-jquery.php – Aswin Murugesh Feb 09 '15 at 08:04