Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python - Compare files

I need to use a get() to select an object by comparing it with a FILE request:

My models:

class Work (models.Model):
    file = models.FileField(storage=OverwriteStorage(), upload_to=path)

class Group(models.Model):
    members = models.ManyToManyField(User, related_name='group_list', null=True, blank=True)

I have tried: var = mygroup.work_list.get(file=request.FILES['file'])

With the same file: Work matching query does not exist

EDIT :

I prefer in reality to compare the name of file but that doesn't works too:

var = mygroup.work_list.get(file__name=request.FILES['file'].name)

EDIT2 :

It seems I can't make a request whith informations about file, I have tried with size Join on field 'file' not permitted. Did you misspell 'size' for the lookup type?I have the same message with name...

like image 912
nlassaux Avatar asked Apr 06 '26 22:04

nlassaux


1 Answers

You can try generating and storing a md5-hash of the file and compare with this key.

like image 107
Thomas Schwärzl Avatar answered Apr 08 '26 12:04

Thomas Schwärzl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!