Opened 14 years ago
Closed 13 years ago
#12304 closed (fixed)
modelForm/unique_together error 'Foo bar with this None and None already exists.'
Reported by: | johnsmith | Owned by: | Ramiro Morales |
---|---|---|---|
Component: | Forms | Version: | 1.1 |
Severity: | Keywords: | ModelForm unique_together unique wwith this None already exists | |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
"Foo bar with this None and None already exists."
Try to save a combination of foo and bar that already exists using the form below and the
error message says "this None and None", comment out the field
overrides and there's no problem.
Not sure whether the problem is with unique_together or ModelForm.
Models
class Foo(models.Model): f = models.IntegerField(unique=True) def __unicode__(self): return 'Foo with f = %d' % self.f class Bar(models.Model): b = models.IntegerField(unique=True) def __unicode__(self): return 'Bar with b = %d' % self.b class FooBar(models.Model): foo = models.ForeignKey('Foo') bar = models.ForeignKey('Bar') class Meta: unique_together = (('foo','bar'),)
Form
class FooBarForm(forms.ModelForm): foo = forms.ModelChoiceField(Foo.objects.all()) # comment this line out an the error message is correct bar = forms.ModelChoiceField(Bar.objects.all()) # comment this line out an the error message is correct class Meta: model = FooBar
Attachments (2)
Change History (8)
comment:1 Changed 13 years ago by
Changed 13 years ago by
Attachment: | 12304-ensure-readable-label-in-unique-validation_error-messages.diff added |
---|
comment:2 Changed 13 years ago by
Has patch: | set |
---|---|
Keywords: | unique wwith this None already exists added |
Owner: | changed from nobody to Ramiro Morales |
Status: | new → assigned |
comment:3 Changed 13 years ago by
Triage Stage: | Unreviewed → Accepted |
---|
comment:4 Changed 13 years ago by
Triage Stage: | Accepted → Ready for checkin |
---|
Changed 13 years ago by
Attachment: | 12304-only-tests-trunk-r12159.diff added |
---|
The previous patch reduced to only contain the regression tests that demonstrate this was solved with the model-validation branch merge
comment:5 Changed 13 years ago by
Current status is:
12304-ensure-readable-label-in-unique-validation_error-messages.diff
-- patch applicable to the 1.1.x branch to fix this issue.12304-only-tests-trunk-r12159.diff
-- Patch for trunk that only adds the regression tests because there the issue was fixed with themodel-validation
branch merge.
comment:6 Changed 13 years ago by
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
#12341 reported this problem also for the unique (not unique_together) error message, plus has some description about what is causing it. The two should be fixed at the same time, so that was closed as a dupe of this.