Opened 8 years ago

Closed 8 years ago

Last modified 5 years ago

#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: UI/UX:

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)

10002.diff (593 bytes) - added by David Gouldin 8 years ago.
10002.2.diff (5.1 KB) - added by David Gouldin 8 years ago.
10002.3.diff (4.8 KB) - added by David Gouldin 8 years ago.

Download all attachments as: .zip

Change History (15)

comment:1 Changed 8 years ago by (none)

milestone: post-1.0

Milestone post-1.0 deleted

comment:2 Changed 8 years ago by Jacob

milestone: 1.1
Triage Stage: UnreviewedAccepted

comment:3 Changed 8 years ago by David Gouldin

Cc: dgouldin@… added

I could not reproduce this behavior. Can anybody else?

comment:4 Changed 8 years ago by Karen Tracey

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 Changed 8 years ago by David Gouldin

Ah, that's different than I had understood from the description. I'll take those models and run with it.

Changed 8 years ago by David Gouldin

Attachment: 10002.diff added

comment:6 Changed 8 years ago by David Gouldin

Has patch: set

comment:7 Changed 8 years ago by David Gouldin

Needs tests: set
Owner: changed from nobody to David Gouldin

Changed 8 years ago by David Gouldin

Attachment: 10002.2.diff added

comment:8 Changed 8 years ago by David Gouldin

Needs tests: unset

Changed 8 years ago by David Gouldin

Attachment: 10002.3.diff added

comment:9 Changed 8 years ago by webiest

I originally reported this. Good job on fixing. Much better description by kmtracey. That was exactly the issue I was having.

comment:10 Changed 8 years ago by Jacob

Triage Stage: AcceptedReady for checkin

comment:11 Changed 8 years ago by Jacob

Resolution: fixed
Status: newclosed

(In [10589]) [1.0.X] Fixed #10002: inline file uploads now correctly display prior data. Thanks, dgouldin. Backport of r10588 from trunk.

comment:12 Changed 5 years ago by Jacob

milestone: 1.1

Milestone 1.1 deleted

Note: See TracTickets for help on using tickets.
Back to Top