Opened 15 years ago
Closed 14 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 by , 15 years ago
by , 15 years ago
Attachment: | 12304-ensure-readable-label-in-unique-validation_error-messages.diff added |
---|
comment:2 by , 15 years ago
Has patch: | set |
---|---|
Keywords: | unique wwith this None already exists added |
Owner: | changed from | to
Status: | new → assigned |
comment:3 by , 15 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:4 by , 15 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
by , 15 years ago
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 by , 15 years ago
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 by , 14 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Note:
See TracTickets
for help on using tickets.
#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.