Code

Opened 5 months ago

Closed 5 months ago

Last modified 5 months ago

#21472 closed Bug (fixed)

Django 1.6 ImageField not rendered properly in Admin inline form

Reported by: agale031176@… Owned by: nobody
Component: Forms Version: 1.6
Severity: Normal Keywords: regression
Cc: agale031176@… Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: yes

Description

Hi

I have a model with ImageFields but the ImageField does not show properly when the model is an inline of another form. Downgrading to django 1.4.9 things are fine. So I think this is an issue with django 1.6.

Attachments (2)

django-1.4.9.png (109.4 KB) - added by anonymous 5 months ago.
django1.6.png (85.9 KB) - added by anonymous 5 months ago.

Download all attachments as: .zip

Change History (11)

comment:1 Changed 5 months ago by timo

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

Could you provide some more details like code to reproduce, a traceback, etc. Have you tested with Django 1.5 to see if the issue exists there?

Changed 5 months ago by anonymous

Changed 5 months ago by anonymous

comment:2 Changed 5 months ago by anonymous

Files attached showing the difference between 1.4.9 and 1.6. Django 1.5 is the same as 1.6. ImageFields inlines are not showing.

comment:3 Changed 5 months ago by timo

Screenshots are nice, but that's not sufficient for us to reproduce the issue to confirm it's actually a problem with Django and not your own code or a 3rd party library. Using the Choice model in the tutorial, I was able to add an inline ImageField just fine.

comment:4 Changed 5 months ago by anonymous

Here is the code that I have that works in 1.4.9 but not in later releases:

In the models.py:

class Property(models.Model):
    property_id = models.IntegerField(primary_key=True, default=0)
    title = models.CharField(max_length=250, null=False)
    village = models.ForeignKey(Village, 'name')

class PropertyImages(models.Model):
    property_id = models.ForeignKey(Property)
    image_path = models.ImageField(null=False, upload_to='test')

Then in the admin.py:

class PropertyImagesAdmin(admin.TabularInline):
    model = PropertyImages
    fields = ['image_path']

class PropertyAdmin(admin.ModelAdmin):
    fields = [
        'title', 'village'
    ]

    inlines = [
        PropertyImagesAdmin,
    ]

admin.site.register(Property, PropertyAdmin)

I am not sure if Django is the problem or I have to do this differently in later version.

Last edited 5 months ago by claudep (previous) (diff)

comment:5 Changed 5 months ago by claudep

  • Triage Stage changed from Unreviewed to Accepted

I could reproduce and can confirm that this happens when object primary key = 0. The cause still needs to be investigated...

comment:6 Changed 5 months ago by claudep

  • Component changed from Uncategorized to Forms
  • Keywords regression added

OK, so this was introduced with the fix for #19524 ([e9c24bef74e5572] and [5097d3c5faab2] (1.5)).
The problem is the test if self.instance.pk: in BaseInlineFormSet.__init__ which should probably be if self.instance.pk is not None:.

comment:7 Changed 5 months ago by akaariai

What about backpatching? This seems to be both in 1.5 and 1.6. Django 1.5 is in security fixes only mode, and this clearly isn't a regression for 1.6. The changes required here seem to be trivial, and possibility for new regressions seems really low, so I vote for backpatch to 1.6.

comment:8 Changed 5 months ago by Claude Paroz <claude@…>

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

In fafb6cf049bb9f4591a8b94cffda12c081cd096f:

Fixed #21472 -- Fixed inline formsets display when parent pk is 0

Thanks agale031176@… for the report.

comment:9 Changed 5 months ago by Claude Paroz <claude@…>

In d8fdee7db877e3a52a761bfcbeb3536ea219ec30:

[1.6.x] Fixed #21472 -- Fixed inline formsets display when parent pk is 0

Thanks agale031176@… for the report.
Backport of fafb6cf049b from master.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.