#8882: Inline model formsets break validation for unique_together with foreign
keys
----------------------------------------------+-----------------------------
Reporter: [EMAIL PROTECTED] | Owner: nobody
Status: new | Milestone:
Component: Forms | Version: 1.0
Resolution: | Keywords:
Stage: Accepted | Has_patch: 0
Needs_docs: 0 | Needs_tests: 0
Needs_better_patch: 0 |
----------------------------------------------+-----------------------------
Changes (by mrts):
* summary: Unique and Unique together in admin inlines are not working
=> Inline model formsets break validation for
unique_together with foreign keys
Comment:
Given the following `models.py`:
{{{
from django.db import models
from django import forms
from django.contrib import admin
class Foo(models.Model):
foo = models.CharField(max_length=100)
# test for unique
class Bar(models.Model):
foo = models.ForeignKey(Foo)
bar = models.CharField(max_length=100, unique=True)
# test for unique_together
class Baz(models.Model):
foo = models.ForeignKey(Foo)
baz = models.CharField(max_length=100)
class Meta:
unique_together = ("foo", "baz")
class BarInline(admin.StackedInline):
model = Bar
class BazInline(admin.StackedInline):
model = Baz
class FooAdmin(admin.ModelAdmin):
inlines = (BarInline, BazInline)
admin.site.register(Foo, FooAdmin)
}}}
Test case 1 -- '''the database is empty''':
* adding `Bar.bar = 'a'` twice results in `IntegrityError at
/admin/uniq/foo/add/ -- column bar is not unique`,
* adding a single `Bar.bar = 'a'` and consequently adding `Baz.baz = 'a'`
twice results in `IntegrityError at /admin/uniq/foo/1/ -- columns foo_id,
baz are not unique`
Test case 2 -- '''there is already a `Bar` with `Bar.bar = 'a'`''':
* adding `Bar.bar = 'a'` again is correctly validated and `Bar with this
Bar already exists.` displayed,
* adding a single `Bar.bar = 'b'` and consequently adding `Baz.baz = 'a'`
twice results in `IntegrityError at /admin/uniq/foo/1/ -- columns foo_id,
baz are not unique`
--
Ticket URL: <http://code.djangoproject.com/ticket/8882#comment:5>
Django Code <http://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 post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---