On Aug 15, 2:54 am, George Laskowsky <[email protected]> wrote: > I have the following code (simplified): > > # models.py > > class Historico(models.Model): > fechaCreacion = models.DateTimeField(auto_now_add=True) > fechaModificacion = models.DateTimeField(auto_now=True) > > class Meta: > abstract = True > > class Categoria(Historico): > nombre = models.CharField(max_length = 20) > descripcion = models.CharField(max_length = 50, blank = True, > verbose_name = 'descripción') > > def __unicode__(self): > return self.nombre > > class Meta: > ordering = ['nombre'] > > # forms.py > > class CategoriaForm(forms.ModelForm): > class Meta: > model = Categoria > > # views.py > [lots of code, variable 'data' is loaded with data from a file] > form = CategoriaForm( initial=data , prefix=str(idx) ) > if form.is_valid(): > [do something] > else: > [do another thing] > [/lots of code] > > The webpage shows the form populated with the data, BUT, is_valid() always > return false. I don't know what fails to validate, form.errors is empty. > > Thanks! > > P.S: thanks Margie for the last help.
By passing in initial, you are creating an unbound form. This will never validate - as the documentation says, initial data is never used in place of actual data to populate a form, it's simply used for display purposes. See the documentation here: http://docs.djangoproject.com/en/dev/ref/forms/api/ for a discussion about the differences between bound and unbound forms and how the initial and data parameters are used. I think you might need to show your whole view function, because it looks like you are getting a bit confused about the flow. The standard view function is shown here: http://docs.djangoproject.com/en/dev/topics/forms/#using-a-form-in-a-view -- DR. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---

