admin list_editable with unique_together raises Integrity Error
|Reported by:||Sławek Ehlert||Owned by:||nobody|
|Severity:||Normal||Keywords:||list_editable unique_together IntegrityError|
|Cc:||Oroku Saki, Sebastian Goll, carsten.fuchs@…, someuniquename@…||Triage Stage:||Accepted|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||yes|
I'm getting an Integrity Error when trying to edit (on changelist) a model that has some unique_together fields and is
registered with list_editable containing some of that fields (not all of them).
#models.py class Test(models.Model): t1 = models.CharField(max_length=255, blank=True, null=True) t2 = models.CharField(max_length=255, blank=True, null=True) t3 = models.CharField(max_length=255, blank=True, null=True) class Meta: unique_together = ['t1','t2','t3'] #admin.py class TestAdmin(admin.ModelAdmin): list_display = ['t3', 't1', 't2'] list_editable = ['t1', 't2',] admin.site.register(Test, TestAdmin)
the changelist form (?) doesn't check the uniqueness of an edited record.
Integrity Error is raised when for example having two rows -
first: t1 = 'a', t2 = 'b', t3 = 'z'
and second: t1 = 'a', t2 = 'a', t3 = 'z'
and trying to change the t2 in first row to 'a'.
In case when all fields from unique_together are in list_editable, the error message does show. However it isn't very informative (only "Please correct the errors below." but nothing below is indicated).
Done this on sqlite3 and PostgreSQL.
Change History (29)
comment:1 follow-up: 2 Changed 7 years ago by
|Patch needs improvement:||unset|
|Triage Stage:||Unreviewed → Design decision needed|