lehins / django-smartfields

Django Model Fields that are smart.
MIT License
98 stars 13 forks source link

Django admin inlines #7

Closed xtrinch closed 8 years ago

xtrinch commented 8 years ago

The images are not processed (resized) when uploaded through the django TabularInline form.

lehins commented 8 years ago

It could be that Django does some bulk update with TabularInline form, but I will have to investigate it in more detail. Is it possible that you can include relevant code snippets, it would be very helpful.

xtrinch commented 8 years ago
class Photo(models.Model):
    rating = models.ForeignKey(Rating)
    photo = fields.ImageField(upload_to='static/photos', null=True, dependencies=[
        FileDependency(processor=ImageProcessor(
            format='JPEG', scale={'max_width': 300, 'max_height': 300}))
    ])

class PhotoInline(admin.TabularInline):
    model = Photo
    extra = 0

class RatingAdmin(admin.ModelAdmin):
    list_display = ('id','rating_date','token_user', 'token_shop', 'rating')

    inlines = [
        PhotoInline
    ]
lehins commented 8 years ago

@xtrinch, thank you. I'll look into the problem this weekend.

andybak commented 8 years ago

I'm fairly certain inlines don't trigger any bulk ORM actions (which would bypass smartfields)

lehins commented 8 years ago

@andybak, yes bulk ORM actions would definitely bypass smartfields, and yes inlines don't trigger any actions.

lehins commented 8 years ago

@xtrinch, unfortunately I cannot replicate your problem. I've created same models and used same code for admin. Attached is the screenshot. Images are converted and resized as expected (notice .jpg extension, I was uploading .png's) What's the version of Django you are using and version of Pillow library? Does it resize images when you upload using regular forms?

screenshot from 2016-02-11 17-59-05

lehins commented 8 years ago

@xtrinch, as a side note and unrelated to this issue, you shouldn't use null=True on file fields, use blank=True instead, since as far as database is concerned it is simple VARCHAR field. https://docs.djangoproject.com/en/1.9/ref/models/fields/#null

lehins commented 8 years ago

I guess I am closing the issue since it cannot be replicated.