Opened 15 years ago

Closed 15 years ago

#13762 closed (duplicate)

Setting prefix on a ModelForm causes is_valid() to return False

Reported by: Mark Tranchant Owned by: nobody
Component: Uncategorized Version: dev
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Setting the prefix attribute on a ModelForm causes validation to fail. Here's a model and its associated form in the project I'm working on. Note that I've excluded the two foreign keys from the ModelForm, leaving just the text.

class RptTField(models.Model):
        report = models.ForeignKey(Rpt)
        config = models.ForeignKey(RptCfgTField)
        text = models.TextField()


class RptTForm(forms.ModelForm):
        class Meta:
                model = RptTField
                exclude = ('report','config')


>>> from myproj.models import *
>>> a = RptTForm({'text':'hello world'})
>>> a.prefix
>>> a.is_valid()
True
>>> b = RptTForm({'text':'hello world'},prefix='abc')
>>> b.prefix
'abc'
>>> b.is_valid()
False

I can't see anything in the docs that explains this behaviour. I need this as I'm bundling multiple ModelForms into one HTML form, and need to put the prefix in when binding to the POST data in case validation fails and the form needs re-drawing. This is with the latest SVN, 13353.

Change History (1)

comment:1 by Mark Tranchant, 15 years ago

Resolution: duplicate
Status: newclosed
Note: See TracTickets for help on using tickets.
Back to Top