Opened 8 years ago

Closed 7 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: dgouldin
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:


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).


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)


class ExampleInline(admin.TabularInline):
    model = Example

class TestAdmin(admin.ModelAdmin):
    inlines = [ExampleInline,], TestAdmin)

Attachments (3)

10002.diff (593 bytes) - added by dgouldin 7 years ago.
10002.2.diff (5.1 KB) - added by dgouldin 7 years ago.
10002.3.diff (4.8 KB) - added by dgouldin 7 years ago.

Download all attachments as: .zip

Change History (15)

comment:1 Changed 8 years ago by anonymous

  • milestone post-1.0 deleted

Milestone post-1.0 deleted

comment:2 Changed 8 years ago by jacob

  • milestone set to 1.1
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

comment:3 Changed 7 years ago by dgouldin

  • Cc dgouldin@… added

I could not reproduce this behavior. Can anybody else?

comment:4 Changed 7 years ago by kmtracey

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):

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

class FileTInline(admin.TabularInline):
    model = FileT

class FCollectionAdmin(admin.ModelAdmin):
    inlines = [FileTInline], 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 7 years ago by dgouldin

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

Changed 7 years ago by dgouldin

comment:6 Changed 7 years ago by dgouldin

  • Has patch set

comment:7 Changed 7 years ago by dgouldin

  • Needs tests set
  • Owner changed from nobody to dgouldin

Changed 7 years ago by dgouldin

comment:8 Changed 7 years ago by dgouldin

  • Needs tests unset

Changed 7 years ago by dgouldin

comment:9 Changed 7 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 7 years ago by jacob

  • Triage Stage changed from Accepted to Ready for checkin

comment:11 Changed 7 years ago by jacob

  • Resolution set to fixed
  • Status changed from new to closed

(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 deleted

Milestone 1.1 deleted

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