Python – Compare files

Question:

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…

Asked By: nlassaux

||

Answers:

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

Answered By: Thomas Schwärzl

I have found : var = mygroup.work_list.get(file=path+'/'+request.FILES['file'].name)

Answered By: nlassaux
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.