Opened 16 years ago

Last modified 13 years ago

#8795 closed

bug in form validation — at Initial Version

Reported by: anihrat@… Owned by: nobody
Component: Forms Version: dev
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

i found this bug

when you have model like this:

class FunkcjeProdukt(models.Model):

funkcja = models.ForeignKey(FunkcjeRodzina)
produkt = models.ForeignKey(Produkty)
wartosc = models.CharField(max_length=255)
class Meta:

unique_together = ("produkt", "funkcja")

and form from model:
class FunkcjeProduktForm(ModelForm):

wartosc = forms.CharField(widget=forms.TextInput(attrs={'size':'40','class':'formularz'}))
class Meta:

model = FunkcjeProdukt
exclude=('produkt','funkcja')

end if you want only edit "wartosc" from existing instance:
form_fp = FunkcjeProduktForm(data=request.POST,instance=finst)
if form_fp.is_valid():

form_fp.save()

error is throw:

KeyError at /cms/r_produkt/8/
'produkt'Request Method: POST
Request URL: http://posiflex.com.pl/cms/r_produkt/8/
Exception Type: KeyError
Exception Value: 'produkt'
Exception Location: /home/posiflex/django/forms/models.py in validate_unique, line 238

because:
in validate_unique() from django/forms/models.py
line unique_checks = list(self.instance._meta.unique_together[:])
add 'produkt' and 'funkcja' even when this fields in on exclude list

Change History (0)

Note: See TracTickets for help on using tickets.
Back to Top