﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
25987	Creating new object in admin with child model inlines and unique_together raises IntegrityError	Anton	Simon Charette	"I'm getting an IntegrityError when trying to create a model (ParentModel) with inlines for ChildModel which have unique_together constraint on (ParentModel, some_field). 

When ParentModel object already exists and I try to add duplicates for ChildModel, BaseModelFormSet.validate_unique() nicely prevents me to save data and prints the standard django adminsite error ""Please correct the duplicate values below"" with concrete message for duplicate inline rows ""'Please correct the duplicate data for some_field"".

models.py:
{{{#!python
from django.db import models


class ParentModel(models.Model):
    title = models.CharField(max_length=100, verbose_name='Title')


class ChildModel(models.Model):
    parent = models.ForeignKey(ParentModel, verbose_name='Link to parent')
    some_field = models.IntegerField(verbose_name='Some numeric field for unique_together')

    class Meta:
        unique_together = (('parent', 'some_field'), )

}}}

admin.py:
{{{#!python
from django.contrib import admin
from .models import *


class ChildModelFormInline(admin.TabularInline):
    model = ChildModel


class ParentModelAdmin(admin.ModelAdmin):
    inlines = (ChildModelFormInline, )


class ChildModelAdmin(admin.ModelAdmin):
    pass


admin.site.register(ParentModel, ParentModelAdmin)
admin.site.register(ChildModel, ChildModelAdmin)
}}}

I think it's important issue. If our ""ParentModel"" has many ""ChildModels"" with many fields and inlines, people don't want lose their data on http 500 due to IntegriryError. Googling gives me workarounds only.

Done this on Django 1.7.11, 1.8.7 and 1.9 with SQLite (3.8.2 2013-12-06) and PostgreSQL (9.4.3)"	Bug	closed	Forms	dev	Normal	fixed	admin, create object, unique_together, IntegrityError, validate_unique		Ready for checkin	1	0	0	0	0	0
