Opened 10 years ago

Closed 10 years ago

Last modified 7 years ago

#9545 closed (worksforme)

FileField: height_field and width_field are not working

Reported by: julian24 Owned by: nobody
Component: File uploads/storage Version: 1.0
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


With this model height_field and width_field aren't working:

class Wallpaper(models.Model):
        title = models.CharField(_('Title'), max_length=80)
        wallpaper = models.ImageField(_('Wallpaper'),
          upload_to = 'wallpapers/',
          height_field = 'wallpaper_height',
          width_field = 'wallpaper_width')
        wallpaper_height = models.IntegerField(_('Wallpaper height'), blank=True, null=True)
        wallpaper_width = models.IntegerField(_('Wallpaper width'), blank=True, null=True)
        def __unicode__(self):
                return unicode(self.title)

But if I add the following save method, it works fine:

        def save(self):
                if self.wallpaper.field.width_field:
                        setattr(self.wallpaper.instance, self.wallpaper.field.width_field, self.wallpaper.width)
                if self.wallpaper.field.height_field:
                        setattr(self.wallpaper.instance, self.wallpaper.field.height_field, self.wallpaper.height)
                super(Wallpaper, self).save()

Change History (5)

comment:1 Changed 10 years ago by Karen Tracey

What does "aren't working" mean? Is this possibly the same as #8208?

comment:2 Changed 10 years ago by julian24

It means that the fields are empty.

comment:3 Changed 10 years ago by Jacob

milestone: 1.1
Triage Stage: UnreviewedAccepted

comment:4 Changed 10 years ago by Alex Gaynor

Resolution: worksforme
Status: newclosed

There are now several tests for this, I'm going to mark as worksforme, if you can show case where it doesn't work please reopen with a testcase.

comment:5 Changed 7 years ago by Jacob

milestone: 1.1

Milestone 1.1 deleted

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