Search code examples
pythonfilecomparison

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...


Solution

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