#10002 closed (fixed)
Data does not display in TabularInline when validation fails for an ImageField
Reported by: | anonymous | Owned by: | David Gouldin |
---|---|---|---|
Component: | contrib.admin | Version: | 1.0 |
Severity: | Keywords: | TabularInline, ImageField | |
Cc: | dgouldin@… | 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
I have a TabularInline form associated with a model in my admin and it has an ImageField and a CharField. When I edit / add a record to the list and do not upload an image, Click save and edit, it throws an error "This field is required" and wipes out all of the previous data (the data is not lost, it just doesn't appear in the list).
---model:
class Example(models.Model): name = models.CharField(max_length=128) test = models.ForeignKey(Test, related_name="examples") image = models.ImageField(upload_to=settings.UPLOAD_TO)
---admin:
class ExampleInline(admin.TabularInline): model = Example class TestAdmin(admin.ModelAdmin): inlines = [ExampleInline,] admin.site.register(Test, TestAdmin)
Attachments (3)
Change History (15)
comment:1 by , 16 years ago
milestone: | post-1.0 |
---|
comment:2 by , 16 years ago
milestone: | → 1.1 |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:4 by , 16 years ago
I can recreate a problem, not entirely sure it is exactly what was originally reported. Given these models:
class FCollection(models.Model): name = models.CharField(max_length=22) def __unicode__(self): return self.name class FileT(models.Model): coll = models.ForeignKey(FCollection) rating = models.IntegerField() ifile = models.ImageField(upload_to=u'uploaded_files') def __unicode__(self): return u'%s: %s' % (unicode(self.coll), self.ifile)
and this admin.py:
class FileTInline(admin.TabularInline): model = FileT class FCollectionAdmin(admin.ModelAdmin): inlines = [FileTInline] admin.site.register(FCollection, FCollectionAdmin)
Recreate by first creating an FCollection and uploading one file. Then, attempt to add a 2nd, but only fill in the rating, don't actually upload a file. Upon hitting any of the save buttons, the page will get re-displayed with the "This field is required" and "Please correct the error below" messages (both fine), but also the widget for the 1st file will no longer show that the first inline object has an associated file. That is, it will no longer have "Currently: whatever_file_name" nor the "Change:" label next to the file chooser input box.
So, I see that the existing data for the already-uploaded file fields appears to vanish, but I'm not sure if there was more vanishing going on in the original report which says "wipes out all the previous data". It's only the existing file field data that isn't displayed, the rest of the fields display properly. Also it is just that the data is not being shown, it hasn't been lost: if you go back and reload the page from scratch or fix the required error by choosing a file to upload and saving, then again all of the uploaded file information is displayed on the page.
comment:5 by , 16 years ago
Ah, that's different than I had understood from the description. I'll take those models and run with it.
by , 16 years ago
Attachment: | 10002.diff added |
---|
comment:6 by , 16 years ago
Has patch: | set |
---|
comment:7 by , 16 years ago
Needs tests: | set |
---|---|
Owner: | changed from | to
by , 16 years ago
Attachment: | 10002.2.diff added |
---|
comment:8 by , 16 years ago
Needs tests: | unset |
---|
by , 16 years ago
Attachment: | 10002.3.diff added |
---|
comment:9 by , 16 years ago
I originally reported this. Good job on fixing. Much better description by kmtracey. That was exactly the issue I was having.
comment:10 by , 16 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
comment:11 by , 16 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Milestone post-1.0 deleted