check if DB field is null

I am trying to see if the field is null or not:

def detail(request, pk):
	photos = Photo.objects.get(id=pk)
	the_file = photos.doc_file
	if the_file is None:
		no_file = 1
	else:
		no_file = 0

it is not working.

What is in the field that you are testing?

Is doc_file a FileField field? How is it defined in your model?

Yes file field imy model with null and blank false by

If the field is null=False and blank=False, then you will never have a Null in that field.

I’m not sure what the issue is then.

I am checking if null I won’t display a link and if not null I will display a link.

But it will never be null, because you don’t allow it in the field.

I don’t understand what the issue is.

Ok if otherwise null is set to true how to check if it’s null or not

The condition you have would work.

Thanks I was blinded not seeing that by trying to make the opposite

for some reason it didn’t work.
Using “if not” worked:

{% if not photos.doc_file %}
    <p>Description: {{photos.description}}</p>
{% else %}
    <p>Description: {{photos.description}}</p>
    <a href="https://mmm.com/{{photos.doc_file}}">File Download</a>
{% endif %}