#31932: unique_together with a formset prompt a wrong validation
-------------------------------------+-------------------------------------
Reporter: taifu | Owner: nobody
Type: Bug | Status: new
Component: Forms | Version: 3.1
Severity: Normal | Keywords: formset, inline,
Triage Stage: | unique_together
Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Validation of a formset with a unique_together doesn't take deleted
children into account.
Method is_valid of forms/formset.py::BaseFormSet should take in account
deleted children forms to prevent a wrong validation error.
{{{
#!div style="font-size: 80%"
Simple models.py:
{{{#!python
from django.db import models
from django.utils.translation import ugettext as _
class Book(models.Model):
title = models.CharField(max_length=64, verbose_name=_("Title"))
class Language(models.Model):
language = models.CharField(max_length=64, verbose_name=_("Language"))
class Translator(models.Model):
name = models.CharField(max_length=64, verbose_name=_("Name"))
book = models.ForeignKey(Book, on_delete=models.CASCADE)
language = models.ForeignKey(Language, on_delete=models.CASCADE)
class Meta:
unique_together = ('book', 'language')
}}}
}}}
{{{
#!div style="font-size: 80%"
Simple admin.py:
{{{#!python
from django.contrib import admin
from .models import Book, Language, Translator
class TranslatorInline(admin.TabularInline):
model = Translator
@admin.register(Book)
class BookAdmin(admin.ModelAdmin):
inlines = [TranslatorInline]
@admin.register(Language)
class LanguageAdmin(admin.ModelAdmin):
pass
}}}
}}}
Wrong validation error:
[[Image(unique-together-formset.png)]]
--
Ticket URL: <https://code.djangoproject.com/ticket/31932>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/048.cc521893a855ef3763a3dac2ce7728bf%40djangoproject.com.