django-cms / django-filer

File and Image Management Application for django
https://django-filer.readthedocs.io/
Other
1.76k stars 577 forks source link

Select a valid choice error when choosing a video file in admin #1445

Open AoNoOokami opened 8 months ago

AoNoOokami commented 8 months ago

Hello, I'm trying to implement django-filer 3.1.1 to manage video files with Django REST Framework. I followed the Usage and Extending Django Filer explanations. I can upload videos, but when I want to assign them to a model that uses them in the admin console, I have the Select a valid choice. That choice is not one of the available choices. error and I can't figure out why it happens.

settings.py:

INSTALLED_APPS = [
    ...
    'django.contrib.staticfiles',
    ...
    'easy_thumbnails',
    'filer',
]

# Files
FILER_PAGINATE_BY = 15

models.py

from django.db import models

from filer.models.filemodels import File
from filer.fields.file import FilerFileField

class Video(File):
    @classmethod
    def matches_file_type(cls, iname, ifile, mime_type):
        video_types = ['application/vnd.dvb.ait', 'video/x-sgi-movie', 'video/mp4', 'video/mpeg',
                    'video/x-msvideo', 'video/x-ms-wmv', 'video/ogg', 'video/webm', 'video/quicktime']
        return mime_type in video_types

class FilerVideoField(FilerFileField):
    default_model_class = Video

...

class Sign(models.Model):
    # Some other fields
    front_reference_video = FilerVideoField(null=True, blank=True,
                                related_name="front_reference_video",
                                on_delete=models.CASCADE)
    side_reference_video = FilerVideoField(null=True, blank=True,
                                related_name="side_reference_video",
                                on_delete=models.CASCADE)

    class Meta:
        ordering = ['id']

urls.py

urlpatterns = [
    # Urls
]

urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

admin.py

from filer.admin.fileadmin import FileAdmin

from .models import User, Sign, Video

...

admin.site.register(Video, FileAdmin)

requirements.txt may be useful:

asgiref==3.7.2
attrs==23.2.0
autobahn==23.6.2
Automat==22.10.0
certifi==2023.11.17
cffi==1.16.0
channels==4.0.0
chardet==5.2.0
charset-normalizer==3.3.2
constantly==23.10.4
cryptography==41.0.7
cssselect2==0.7.0
daphne==4.0.0
Deprecated==1.2.14
Django==4.2.8
django-cors-headers==4.3.1
django-filer==3.1.1
django-filter==23.5
django-lti==0.4.0
django-polymorphic==3.1.0
djangorestframework==3.14.0
drf-yasg==1.21.7
easy-thumbnails==2.8.5
hyperlink==21.0.0
idna==3.6
incremental==22.10.0
inflection==0.5.1
jwcrypto==1.5.1
lxml==5.1.0
Markdown==3.5.2
packaging==23.2
pillow==10.2.0
psycopg==3.1.15
pyasn1==0.5.1
pyasn1-modules==0.3.0
pycparser==2.21
PyJWT==2.8.0
PyLTI1p3==2.0.0
pyOpenSSL==24.0.0
pytz==2023.3.post1
PyYAML==6.0.1
reportlab==4.0.9
requests==2.31.0
service-identity==24.1.0
six==1.16.0
sqlparse==0.4.4
svglib==1.5.1
tinycss2==1.2.1
Twisted==23.10.0
txaio==23.1.1
typing_extensions==4.9.0
uritemplate==4.1.1
urllib3==2.1.0
webencodings==0.5.1
wrapt==1.16.0
zope.interface==6.1

Screenshot from 2024-01-30 11-02-04

Screenshot from 2024-01-30 11-02-54

Screenshot from 2024-01-30 11-02-30

Screenshot from 2024-01-30 11-05-53

Any comment to resolve this issue is welcome.

fsbraun commented 8 months ago

I can imagine this error happening if the field you're filling requires an image - not video. The error message is cryptic, but I assume that the mime type is not of a valid choice...

AoNoOokami commented 8 months ago

Actually this issue happens as soon I set default_model_class = Video. If I set it as File the issue disappears. As a workaround, I`m using the FilerFileField with FILER_MIME_TYPE_WHITELIST to allow videos only. That's ok for our particular needs.

stale[bot] commented 5 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

i-salameh95 commented 3 months ago

The same issue happened with me, I have followed the django-filer doc. to add Video Model

stale[bot] commented 2 weeks ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.