How to compare two image field properly

133 views
Skip to first unread message

Sencer Hamarat

unread,
Feb 19, 2022, 5:29:18 AM2/19/22
to django...@googlegroups.com
Hi,

I have two different models which include image fields individually.

Is there a proper way to compare those imagefileds?

class ModelA(models.Model):
    file = models.ImageField(
        verbose_name=_('File'),
        blank=False,
        null=False,
        max_length=400
    )

class ModelB(models.Model):
    image = ImageField(
        verbose_name=_('Product Image'),
        max_length=400,
        default=static('images/default_thumbnail.png'),
    )


Also, I need to figure out how to track any change in a single image field.

Regards,
Sencer HAMARAT

tlockh...@gmail.com

unread,
Feb 19, 2022, 1:56:17 PM2/19/22
to django...@googlegroups.com
OpenCV

- Tom

On Feb 19, 2022, at 2:27 AM, Sencer Hamarat <sencer...@gmail.com> wrote:


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CACp8TZhoLKhfpdn7UcrWajf%2BZ8snaNvFB8M29p4nF5eZ2f7iEg%40mail.gmail.com.

Sencer Hamarat

unread,
Feb 21, 2022, 11:16:42 AM2/21/22
to django...@googlegroups.com
Thanks but, no.
I didn't mean the comparing content of the files.

19 Şub 2022 Cmt 21:55 tarihinde <tlockh...@gmail.com> şunu yazdı:

Azzam Codes

unread,
Feb 27, 2022, 10:33:00 AM2/27/22
to Django users
one way that i know, not sure if best way to do it, 
but you could first extract the fields of your model as:
`modelAFields =  ModelA._meta.fields`
`modelBFields =  ModelB._meta.fields`

then extract your image field eg.:
`imageAField = modelAFields[0]`
`imageBField = modelBFields[0]`

then to display all the field's atributes and loop through them for comparing by :
`vars(imageAField)`
`vars(imageBField)`

Regards, Azzam.

Muhammad Juwaini Abdul Rahman

unread,
Feb 28, 2022, 9:09:11 PM2/28/22
to django...@googlegroups.com
If the image data is huge, that could take a long time.

Maybe you can just compare the checksum?

Reply all
Reply to author
Forward
0 new messages