Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#12532 closed (worksforme)

empty inline forms with FileField are never ignored

Reported by: Flavio Curella Owned by: nobody
Component: contrib.admin Version: 1.1
Severity: Keywords: inline admin formsets
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no



class Album(models.Model):
  name = Charfield(max_length=100)

class Song(models.Model):
  title = CharField(max_length=100)
  audio = FileField()
  album = ForeignKey(Album)

class SongInline(admin.StackedInline):
  model = Song
  extra = 3
class AlbumAdmin(models.ModelAdmin):
  inlines=[SongInline], AlbumAdmin)

Every time I edit an save an Album, Django expect every inline forms to have its file.

Moreover, if I specify null=True, blank=True on the FileField declaration, with every save it creates 3 new Song objects associated with the Album

Change History (2)

comment:1 Changed 10 years ago by Karen Tracey

Resolution: worksforme
Status: newclosed

I cannot recreate what you describe. Tried both Django 1.1.1 and 1.2 alpha. In both cases I can save an album with empty inlines without problem. I can edit an existing Album that has one inline, change the Title of the inline song but not specify a file to re-upload, and it keeps the existing value for the uploaded file.

I suspect you have abbreviated/simplified whatever you are really doing beyond the point where the problem that you are seeing can be observed. Taking exactly what you post above and attempting to use it verbatim requires several fixups (missing upload_to on the FileField, missing models in front of the field types, models.ModelAdmin instead of admin.ModelAdmin) before it will work at all. I'm guessing what you actually are using does not have these errors but does have something else that is essential to causing the problem.

comment:2 Changed 10 years ago by Flavio Curella

Upon further investigation, I found the root of cause being the third-party transdb (duh). I had a TransText field that it gets populated automatically with an empy JSON array (old code, at that time this was the better solution).

Thank you and sorry about wasting your time.

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