From e1e20a8afdf56fec548bce5b627448b6e3594dbd Mon Sep 17 00:00:00 2001 From: Daniel Gray Date: Mon, 22 Apr 2024 08:35:29 +0200 Subject: [PATCH] added hide show to mime_type field --- app/general/admin.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/general/admin.py b/app/general/admin.py index 2c861928..fe219969 100644 --- a/app/general/admin.py +++ b/app/general/admin.py @@ -1,7 +1,7 @@ import mimetypes from django.contrib import admin -from django.forms import ModelForm, fields_for_model +from django.forms import HiddenInput, ModelForm, fields_for_model from .models import DocumentFile, Institution, Language, Project, Subject @@ -18,7 +18,12 @@ class Meta: def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) - self.fields["mime_type"].widget.attrs["disabled"] = True + + # If the instance has a mime_type, the field should be disabled + if not self.instance.mime_type: + self.fields["mime_type"].widget = HiddenInput() + else: + self.fields["mime_type"].widget.attrs["disabled"] = True def clean(self): cleaned_data = super().clean()