Opened 16 years ago

Closed 16 years ago

Last modified 13 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: 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)

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

Download all attachments as: .zip

Change History (15)

comment:1 by (none), 16 years ago

milestone: post-1.0

Milestone post-1.0 deleted

comment:2 by Jacob, 16 years ago

milestone: 1.1
Triage Stage: UnreviewedAccepted

comment:3 by David Gouldin, 16 years ago

Cc: dgouldin@… added

I could not reproduce this behavior. Can anybody else?

comment:4 by Karen Tracey, 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 David Gouldin, 16 years ago

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

by David Gouldin, 16 years ago

Attachment: 10002.diff added

comment:6 by David Gouldin, 16 years ago

Has patch: set

comment:7 by David Gouldin, 16 years ago

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

by David Gouldin, 16 years ago

Attachment: 10002.2.diff added

comment:8 by David Gouldin, 16 years ago

Needs tests: unset

by David Gouldin, 16 years ago

Attachment: 10002.3.diff added

comment:9 by webiest, 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 Jacob, 16 years ago

Triage Stage: AcceptedReady for checkin

comment:11 by Jacob, 16 years ago

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 by Jacob, 13 years ago

milestone: 1.1

Milestone 1.1 deleted

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