home / django_tickets / tickets

tickets: 8795

This data as json

id created changetime last_pulled_from_trac stage status component type severity version resolution summary description owner reporter keywords easy has_patch needs_better_patch needs_tests needs_docs ui_ux
8795 2008-09-02 12:00:55 2011-09-28 16:12:17 2022-03-06 03:43:11.436606 Accepted closed Forms     dev fixed unique_together validation fails on model forms that exclude unique fields i found this bug when you have model like this: {{{ #!python 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: {{{ #!python 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: {{{ #!python form_fp = FunkcjeProduktForm(data=request.POST,instance=finst) if form_fp.is_valid(): form_fp.save() }}} error is throw: {{{ #!python 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 jacob anihrat@gmail.com   0 0 0 0 0 0
Powered by Datasette · Queries took 1.164ms