Skip to content
Advertisement

how to filter images from a list of files in django-rest-framework

I have a Django rest server which server a list of files to react frontend. I would like to know if I can filter those files by images and display only images to my react frontend. I have searched a lot but cannot find anything useful. Please help me. Thank you in advance.

JavaScript

Advertisement

Answer

I finally got it working using this trick.

Added this field in my model.

JavaScript

When a user uploads a file I am checking whether the file is image or not using the following code.

JavaScript

Now I can easily filter files based upon this is_image field.

Please let me know if this is not a good solution..

Thank you for reviewing my question. I really appreciate it.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement