si usted quiere hacer esto antes de que el usuario envía el formulario que tendrá que hacerlo a través de Javascript (jQuery, Mootools, etc. todos ofrecen algunos métodos rápidos para eso)
en el lado Django que podría hacerlo en un método limpio en la forma. Esto debería ayudarlo a comenzar y deberá mostrar esos errores de validación en su plantilla para que el usuario pueda verlos. El nombre del método de limpieza debe coincidir con el nombre del campo de formulario con "limpiar_" antes.
def clean_textBoxFieldName(self):
textInput = self.cleaned_data.get('textBoxFieldName')
fileInput = self.cleaned_data.get('fileFieldName')
if not textInput and not fileInput:
raise ValidationError("You must use the file input box if not entering the full path.")
return textInput
def clean_fileFieldName(self):
fileInput = self.cleaned_data.get('fileFieldName')
textInput = self.cleaned_data.get('textBoxFieldName')
if not fileInput and not textInput:
raise ValidationError("You must provide the file input if not entering the full path")
return fileInput
en la plantilla
{% if form.errors %}
{{form.non_field_errors}}
{% if not form.non_field_errors %}
{{form.errors}}
{% endif %}
{% endif %}
Gracias! que resuelve mi problema :) – tamizhgeek
que he leído en los lugares que no deben CharField's '' null = tienen true' ... ya que '' FileField's son esencialmente CharField's, ¿es realmente el camino a seguir? –