0

I have referred to the similar questions below:

Django - FileField check if None

How to save FileField with None in Django?

Yet I am unable to solve my case.

My model FileField looks like:

document = models.FileField(upload_to=habCompletionDocPath, null=True)

I uploaded a file and deleted.

q = ProgressQty.objects.get(id=id)
q.document = None
q.save()

Now the value of the field is showing None:

In [80]: q.document
Out[80]: <FieldFile: None>

I need to count the number of files uploaded in the table. However, I am unable to do so because of this:

ProgressQty.objects.exclude(document=None)
<ProgressQty: 269891toubul>

as I was expecting <QuerySet []>

How do I get correct result from this code:

objects.annotate(doc=Count('document'))
ron
  • 105
  • 10

1 Answers1

0

Well, I solved my case using:

doc=Count('document', filter=Q(document__gt=0))

Although this might not be the optimal solution.

ron
  • 105
  • 10